Error in picture uploading - php

I have already created directory at location 'cms/user/prescriptionimg' But I am getting error in uploading file.
Warning: move_uploaded_file(../cms/user/prescriptionimg/11500004-21000002-13165874331.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/oxfordmo/public_html/cms/user/prescription.php on line 113
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpdCWdaR' to '../cms/user/prescriptionimg/11500004-21000002-13165874331.jpg' in /home/oxfordmo/public_html/cms/user/prescription.php on line 113
Unable to move user 11500004-21000002-13165874331's picture to prescription directory
Script regarding this is...
if (file_exists("../cms/user/prescriptionimg/$username.$ext"))
{unlink("../cms/user/prescriptionimg/$username.$ext"); }
if (!move_uploaded_file($_FILES["scaninput".$i]['tmp_name'],"../cms/user/prescriptionimg/$username.$ext"))
{ die("Unable to move user $username's picture to prescription directory"); }

use this function to retrieve root path.
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
//-----------------------------------
// require the functions file
//-----------------------------------
//require ("$root/php/funkshions.php");

Related

Failed to open stream: No such file of directory in... PHP fopen

this is my code
include 'connection.php';
setcookie('username',$name,time()+86400,"/");
echo $_COOKIE['username'];
$my_file = '/../../users/'.$name."/index.php";
$handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
when the code runs I want it to create a file with the directory /../../users/[username] where [username] is stored in the $name variable. When I run my code it just gives me a lousy error and it doesn't run any code after line 6 from above.
It won't create the file and the error is...
Warning: fopen(/../../users/codemaster7/index.php) [function.fopen]: failed to open stream: No such file or directory in /nfs/c02/h10/mnt/45563/domains/pizzascripters.com/html/projects/nik/Champion/register/index.php on line 107
Cannot open file: /../../users/codemaster7/index.php
Does anyone have an idea on whats going on and how I can fix it?
1 include 'connection.php';
2 setcookie('username',$name,time()+86400,"/");
3 echo $_COOKIE['username'];
4 $my_file = 'index.php';
5 $handle = fopen($my_file, 'w') or die('Cannot open file: '.$my_file);
I update the directory of file to just a file name in line 4. if you wanna use the directory as a parameter then use the function file($myfile); which return the array of data from your file.
fopen can only create a file at the specified path but it cannot create any directories. You will have to use something like mkdir to create a new directory before you call fopen.
This error often occurs when you miss or misspell something like here I did it first
$path = Yii::getAlias('#common') .'/upload/images/'. $model
Here the spell is upload but it should be uploads as in my project it is uploads. the wrong spell gave me this error. so this often occurs when the path is unknown
$path = Yii::getAlias('#common') .'/uploads/images/'. $model

PHP move_uploaded_file getting errors and file is not being uploaded

I have a form and with input type file....what I am trying to do is save that file to the server (in this case, localhost)
move_uploaded_file($_FILES["image"]["tmp_name"], "/admin-uploads/" . $_FILES["image"]["name"]);
and this is the error I get:
Warning: move_uploaded_file(/admin-uploads/home.jpg): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/Site/admin/Insert.php on line 30
Warning: move_uploaded_file(): Unable to move '/Applications/XAMPP/xamppfiles/temp/phpsoF2wg' to '/admin-uploads/home.jpg' in /Applications/XAMPP/xamppfiles/htdocs/Site/admin/Insert.php on line 30
Am I missing code?
Assuming "/admin-uploads/" directory is a subdirectory of where this script is run. You need the full path to the destination directory.
as:
move_uploaded_file($_FILES["image"]["tmp_name"], __DIR__."/admin-uploads/" . $_FILES["image"]["name"]);
fyi: please be aware that the 'user supplied' [image][name] may not be a valid filename. it may be worthwhile 'sanitizing' it.

PHP failed to open stream: Is a directory

Very simple PHP script I'm running within an EE template on an Ubuntu Webserver I set up personally.
I know it has something to do with permissions, and I've already changed the owner of the directory I'm trying to write as being the Apache user.
<?php
$dir = 'export';
$drop =' {exp:ajw_export
sql="SELECT member_id, screen_name, email FROM exp_members"
format="xml"
} ';
echo $dir;
file_put_contents($dir, $drop);
?>
Error I get is:
A PHP Error was encountered
Severity: Warning
Message: file_put_contents(export): failed to open stream: Is a
directory
Filename: libraries/Functions.php(689) : eval()'d code
Line Number: 16
Your problem is that you're not defining the actual file, only a directory.
$file = $dir . '/export.txt';
file_put_contents($file, $drop);
Otherwise, how will PHP know where to place the content?

failed to open stream : Is a directory in

I am getting the following warnings on trying on move an uploaded file from the temp folder to the desired one using php
Warning: move_uploaded_file(test/) [function.move-uploaded-file]: failed to open stream: Is a directory in /home/..../filename.php on line 69
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpKrCpQw' to 'test/' in /home/..../filename.php on line 69
following are line nos 67 and 69 that are giving the error :
$destination = "test/". $name;
$answer = move_uploaded_file($_FILES['user_file']['tmp_name'],$destination);
It seems like your name is null
$destination = "test/". $name;
echo you name and see what is coimg there.
For me, it was the filesize.
So, check php.ini to see if the uploaded file exceeds upload_max_filesize and post_max_size.
Or maybe add a validation rule in Laravel or js.

PHP: Uploading troubles

I'm making a image uploader but I have come across 2 errors. Which are:
Warning: move_uploaded_file(upload/Corgi 007.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/stationr/public_html/admin/doupload.php on line 12
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/chroot/tmp/phpMvRSbS' to 'upload/Corgi 007.jpg' in /home/stationr/public_html/admin/doupload.php on line 12
The errors are occuring when I call the move_uploaded_file() method. Here is my code (note this has no error checking what so ever it is just bare ones uploading).
<?php
error_reporting(E_ALL);
error_reporting(-1);
ini_set('error_reporting', E_ALL);
$filename = $_FILES["file"]["name"];
$filesize = $_FILES["file"]["size"];
move_uploaded_file($_FILES["file"]["tmp_name"],"upload/$filename");
?>
You've failed to check if the upload succeeded at all:
if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
move file ...
} else {
die("Upload failed with error code " . $_FILES['file']['error']);
}
The error codes are documented here: http://www.php.net/manual/en/features.file-upload.errors.php
As well, is there a "upload" subdirectory in whatever your script's current working directory is? Does the web server process have write permissions on that directory?
And as a MAJOR security hole, blindlly using the ['name'] parameter of the upload as your target filename allows a malicious user to scribble on ANY file on your server. Never ever blindly use that filename. If the upload filename is provided as (say) ../../../../../../etc/passwd, you've now allowed someone to replace your system password file.

Categories