Jump to content

move_uploaded_file works for some files, but not for some others...


brunophilipe

Recommended Posts

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.