i have the following code for uploading the file on my folder and it is working on localhost, but when i uploaded the code online, it's not working though i have put the correct path. Is there any way i could see the reason or error why?
move_uploaded_file($img_tmp,"../images/profile/$post_image1");
What about directory permissions for your destination? Have you cross-checked that?
try chmod -R 777 /var/www/your_project_name
This might help :)
Also, check what's your function move_uploaded_file is returning?
"Returns TRUE on success.
If filename is not a valid upload file, then no action will occur, and move_uploaded_file() will return FALSE.
If filename is a valid upload file, but cannot be moved for some reason, no action will occur, and move_uploaded_file() will return FALSE. Additionally, a warning will be issued."
Sure, refer the below code:
$move = "path_where_you_want_to_save_the_file."
if (move_uploaded_file($_FILES['file']['tmp_name'], $move . $_FILES["file"]['name'])) {
echo "Uploaded";
} else {
echo "File was not uploaded";
}
To check what the function returns:
Just simply use return(move_uploaded_file($img_tmp,"../images/profile/$post_image1"));
Related
Please help me to solve the problem. i'm trying to to upload the image with extension jpg using move_uploaded_file() function. my image upload code is below:
my condition is always become false please help me to solve the issue.
$file_path = '3499738f724b2ae08a1871b6a0a7d175aaaaaaaaaa.jpg';
$fileURL = 'http://demo.deftbit.com/umeedtv/prog_image/';
if(move_uploaded_file($_FILES['vdoImg']['tmp_name'], $fileURL . $file_path)){
echo 'Image Uploading Done.';
}else{
echo 'Image Uploading fail try again later.';
}
Your code does not work, because move_uploaded_file('file tmp path','local root dir path') 2nd para. is wrong. So give root path in file name like
$file_path = '$_SERVER['DOCUMENT_ROOT']'.'your folders/3499738f724b2ae08a1871b6a0a7d175aaaaaaaaaa.jpg';
Please provide directory path not the url path you have provided url path in second parameter that is wrong.
To get current directory path you can use dirname(__FILE__).
I don't think your file path is in the default directory where it is searching for. Try appending the root path to it and see.
I am uploading a file through PHP scipt ..
my code is
$file_temp=$_FILES["upl"]["tmp_name"];
when i upload stuffs with
move_upload_file($file_temp,"user_stuff/".$file_name)
Everything works fine .. stuff get uploaded with no disaster
But when i check the uploaded file to be actually in the area using
is_uploaded_file($file_temp);
It always return false
So i googled the problem and it redirected me to the same stackoverflow problem here
so i did , as it was suggested
if(is_uploaded_file(realpath($file_temp)))
{
echo "done";
}
else
{
echo "fail";
}
But still getting the same problem "fail"
Moreover, i just noticed a strange thing ... when i am not using move_uploaded_file(..) , the is_uploaded_file "works"
try sudo chmod 777 path_to_directory/user_stuff/ -R in your console
The is_uploaded_file function returns false since you are checking the destination of the file which doesn't exist as you have already moved the file to a new location using move_upload_file()
I am trying to upload my php project into public server.
I made the image upload file when I create product or edit product.
It works in localhost, but when I move to public server, it is not working.
I think move_uploaded_file part does not working.
How can I change the link? or do I have to change anything?
When I see Filzilla, I can see remote site that it is '/www/eshopProject/inventory_images'.
And index file is '/www/eshopProject/storeAdmin'.
Do I have to change link like this?
I don't know how can I change the link.
Could you help me? uploading the image into public server is not working..
Is it any security issue? or something?
Please help me. Thanks.
--index.php--
$pid = mysql_insert_id();
//Place image in the folder
$newname = "$pid.jpg";
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/product_$newname");
First of all check the permissions of the directory as mentioned in come of the comments.
If you have shell access "chmod 777 target_dir" or "chmod 707 target_dir" should be sufficient.
Second try to debug it using if's and the file_exists function(http://php.net/manual/en/function.file-exists.php).
Something like this.
$uploadedFile = $_FILES['fileField']['tmp_name'];
$destination = "../inventory_images/product_$newname";
if(file_exists($uploadedFile))
{
echo "file uploaded to temp dir";
}
else
{
echo "file upload failed";
exit();
}
if(move_uploaded_file($uploadedFile, $destination))
{
echo "upload complete";
}
else
{
echo "move_uploaded_file failed";
exit();
}
You can also check your current working directory by using the FILE or DIR constants(http://php.net/manual/en/language.constants.predefined.php).
Try this.
echo __FILE__;
echo dirname(__FILE__);
echo __DIR__;
Use the copy() method. For me it worked.
copy($tmp_file, Destination) or
copy($tmp_image, IMAGE_DIRECTORY . SAM . $product_image);
Make sure you have write file permissions set to the folder you are trying to upload too.
I recommend setting the folders to "755" permissions and retry. This would make the permissions a little tighter.
This question is a bit old but i recently faced a similar issue where even with permission 777 on the upload folder it wouldn't work.
The issue was that the SELinux (https://wiki.centos.org/HowTos/SELinux) was on enforcing mode so i had to change it to permissive mode and then the upload works perfectly.
I hope this can help someone facing this issue.
While uploading images files on the live server I have stuck in a strange issue that the move_uploaded_files() function returns true but the image does not get uploaded.
if(move_uploaded_file($_FILES["img"]["tmp_name"],'./shot_images/'.$_FILES["img"]["name"])){
echo "Success";
}
Here, when executed, prints "Success" but the file is not being uploaded on the specified location.
Any kind of help is appreciated.
If move_uploaded_file is returning true then that indicates the file was moved successfully. Let's try some debugging. What happens when you use the following code:
$dest = "./shot_images/{$_FILES["img"]["name"]}";
if(move_uploaded_file($_FILES["img"]["tmp_name"],$dest)){
$realpath = realpath($dest);
$filesize = filesize($realpath);
echo "Success! Uploaded a $filesize file to $realpath";
}
I suspect it is working, it's just not going where you expect...
If this is the case, it might be due to `'./shot_images/' -- personally I rarely (if ever) use relative paths like that. I find it eliminates confusion if I reference the path to the script:
$dest = dirname(__FILE__)."/shot_images/{$_FILES["img"]["name"]}";
if(move_uploaded_file($_FILES["img"]["tmp_name"],$dest)){
Whenever I try to move a file it does not work and shows "Image file not uploaded"... I just want to know where the error is...
$target = '/var/www/student/public/myimage.jpg';
$destination = '/var/www/student/public/images/myimage.jpg';
if( move_uploaded_file( $target, $destination ) ) {
echo "Image file is successfully loaded";
} else {
echo "Image file not uploaded.";
}
I have checked error log (tail -f /var/log/apache2/error.log) but found nothing.
target and destination both directories have 777 permissions.
Can someone tell me that how to find out the error. Any idea ?
If you are not using HTTP POST upload method then you can use rename()
rename($target, $destination);
Has the file been uploaded in the current request?
move_uploaded_file will refuse to move files that are not uploads. (i.e. $target must equal $_FILES[$field_name]['tmp_name']
If it has been uploaded previously, move_uploaded_file will refuse to work (if it is even still there - PHP will delete it if you don't handle the file on that upload if I remember correctly)
If it is in fact not a file that has been uploaded with this request you'll want to use rename
move_uploaded_file() only works on http post files. http://php.net/manual/en/function.move-uploaded-file.php
to move a file already on the server, you will have to copy the file and unlink the old file
$target = '/var/www/student/public/myimage.jpg';
$destination = '/var/www/student/public/images/myimage.jpg';
if (copy($target, $destination)) {
unlink($target);
} else {
echo "Unable to copy $target to $destination.";
}