brunophilipe Posted September 16, 2011 Share Posted September 16, 2011 Howdy! I have been working in this custom script to manage some people on a group.. It will be really complete, with profiles, related stats and also an simple email client. But recently I have been having an issue with the function move_uploaded_file() to upload a picture to the user's profile. Apparently it works for some files (which means the syntax and paths are correct), but for some others move_uploaded_file() returns FALSE and I just can't work it out. Here is the part of the script that treats the uploading: $target_path = "/opt/lampp/htdocs/emp/deeper/profiles/avt/"; //>>PATH<< to avt folder if (!isAllowedAvatar($_FILES['picture']['name'])) { //Check for allowed filetypes print "<div class='notif error bloc'><strong>Error :</strong> Wrong filetype. Image must be PNG file...</a></div>"; die; } if (file_exists($target_path.$basename.".png")) { //Rename old image to prevent loss of it in case of Failure rename($target_path.$basename.".png",$target_path.$basename."_temp.png"); } $old_path = $target_path; $target_path = $target_path . $basename . ".png"; //Build new image path if(move_uploaded_file($_FILES['picture']['tmp_name'], $target_path)) { //Moves uploaded image print "File ". basename($_FILES['picture']['name'])." correctly uploaded"; unlink($old_path.$basename."_temp.png"); //Deletes temp file } else { print "There was an error uploading the file, please try again!"; rename($old_path.$basename."_temp.png",$old_path.$basename.".png"); //Reverts the temp file to the original } I think the comments are enough for understanding it. Also, it looks like move_uploaded_file() is returning FALSE if the file is from Linux and had ownership stuff.. Any tip is welcome! Thanks for reading! Quote Link to comment https://forums.phpfreaks.com/topic/247240-move_uploaded_file-works-for-some-files-but-not-for-some-others/ Share on other sites More sharing options...
PFMaBiSmAd Posted September 16, 2011 Share Posted September 16, 2011 Find out the reason it is failing by displaying all the php detected errors. Add the following two lines of code immediately after the first opening <?php tag on the page - ini_set("display_errors", "1"); error_reporting(-1); Quote Link to comment https://forums.phpfreaks.com/topic/247240-move_uploaded_file-works-for-some-files-but-not-for-some-others/#findComment-1269758 Share on other sites More sharing options...
brunophilipe Posted September 16, 2011 Author Share Posted September 16, 2011 Nope :/ No error messages appearing. It was interesting because when I refreshed the page it showed me a "PHP Strict" note that I shouldn't rely on the server's Timezone, so the setting worked. But it stills, no error about move_uploaded_file()... Quote Link to comment https://forums.phpfreaks.com/topic/247240-move_uploaded_file-works-for-some-files-but-not-for-some-others/#findComment-1269762 Share on other sites More sharing options...
brunophilipe Posted September 16, 2011 Author Share Posted September 16, 2011 Ok, I feel a kind of stupid now, but the problem wasn't with PHP, but with the HTML form.. <input type='hidden' name='MAX_FILE_SIZE' value='10000' /> 10Kb is too few for a picture Now I have setted it to 1Mb and it works! I hope it helps others too! Thanks anyway for your help Quote Link to comment https://forums.phpfreaks.com/topic/247240-move_uploaded_file-works-for-some-files-but-not-for-some-others/#findComment-1269777 Share on other sites More sharing options...
PFMaBiSmAd Posted September 16, 2011 Share Posted September 16, 2011 Your processing code must check for a successfully uploaded file before it can access any of the uploaded file information. Quote Link to comment https://forums.phpfreaks.com/topic/247240-move_uploaded_file-works-for-some-files-but-not-for-some-others/#findComment-1269779 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.