phplost1989 Posted November 6, 2010 Share Posted November 6, 2010 I'm trying to allow a user to upload an image, and have that image copied to an Image folder on the server When I run the code I get the success message near the bottom of the code, but the image never gets copied to the folder. I'm not sure what's causing it to not copy the image if($_POST["store"] != "") // if upload was hit { $fileExt = strrchr($_FILES['userfile']['name'], "."); // grab extension if($fileExt != ".jpg" && $fileExt != ".jpeg") // check extension { $_SESSION["badFileType"] = "You cannot upload a file of type ".$fileExt; // set error } else { $fileName = $_FILES['userfile']['name']; // set file name if(!is_uploaded_file($_FILES['userfile']['tmp_name'])) { echo "Problem: possible file upload attack!"; // set error exit(); // end } $upfile = "../Images/lg_".$category.$counter.".jpg"; // set path $newFileName = $category.$counter.".jpg"; // set new file name if(!copy($_FILES['userfile']['tmp_name'], $upfile)) // if not able to copy { echo "Problem: file could not be copied to directory!"; // set error exit(); // end } $_SESSION["badfileType"] = "File uploaded successfully!"; // set success message } } else { $_SESSION["badFileType"] = ""; // clear error } Link to comment https://forums.phpfreaks.com/topic/217938-uploading-an-image-and-copying-it-to-a-folder/ Share on other sites More sharing options...
BlueSkyIS Posted November 6, 2010 Share Posted November 6, 2010 check permissions on destination directory and/or try a full path instead of relative. Link to comment https://forums.phpfreaks.com/topic/217938-uploading-an-image-and-copying-it-to-a-folder/#findComment-1131086 Share on other sites More sharing options...
phplost1989 Posted November 6, 2010 Author Share Posted November 6, 2010 permissions are setup and I just tried a full path, but still no image being copied to the folder Link to comment https://forums.phpfreaks.com/topic/217938-uploading-an-image-and-copying-it-to-a-folder/#findComment-1131088 Share on other sites More sharing options...
phplost1989 Posted November 7, 2010 Author Share Posted November 7, 2010 Any other ideas? Link to comment https://forums.phpfreaks.com/topic/217938-uploading-an-image-and-copying-it-to-a-folder/#findComment-1131216 Share on other sites More sharing options...
BlueSkyIS Posted November 7, 2010 Share Posted November 7, 2010 check $upfile and make sure it's what you expect. try move()? Link to comment https://forums.phpfreaks.com/topic/217938-uploading-an-image-and-copying-it-to-a-folder/#findComment-1131230 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.