proctk Posted February 21, 2007 Share Posted February 21, 2007 Hi I'm trying to use the below code to upload images into a file folder called adImage I'm getting this error message Warning: copy(C:/Program Files/xampp/htdocs/adImages/dvdPlayer.jpg) [function.copy]: failed to open stream: No such file or directory in C:\Program Files\xampp\htdocs\etreasures\portal\addTreasure.php on line 36 upload failed! n line 36 = $res = copy($HTTP_POST_FILES['file']['tmp_name'], $path . $HTTP_POST_FILES['file']['name']); $path = $_SERVER['DOCUMENT_ROOT'] . '/adImages/'; $max_file_size = 300000; if(isset ($_POST['Submit'])){ if (!isset($HTTP_POST_FILES['file'])) exit; if (is_uploaded_file($HTTP_POST_FILES['file']['tmp_name'])) { if ($HTTP_POST_FILES['file']['size']>$max_file_size) { echo "The file is too big<br>n"; exit; } if (($HTTP_POST_FILES['file']['type']=="image/gif") || ($HTTP_POST_FILES['file']['type']=="image/pjpeg") || ($HTTP_POST_FILES['file']['type']=="image/jpeg") || ($HTTP_POST_FILES['file']['type']=="image/png")) { if (file_exists($path . $HTTP_POST_FILES['file']['name'])) { echo "The file already exists<br>n"; exit; } $res = copy($HTTP_POST_FILES['file']['tmp_name'], $path . $HTTP_POST_FILES['file']['name']); if (!$res) { echo "upload failed!<br>n"; exit; } else { echo "upload sucessful<br>n"; } echo "File Name: ".$HTTP_POST_FILES['file']['name']."<br>n"; echo "File Size: ".$HTTP_POST_FILES['file']['size']." bytes<br>n"; echo "File Type: ".$HTTP_POST_FILES['file']['type']."<br>n"; } else { echo "Wrong file type<br>n"; exit; } $image = $HTTP_POST_FILES['file']['name']; Quote Link to comment https://forums.phpfreaks.com/topic/39395-upload-image-problem/ Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 Try making your copy statement all on one line. [Edit] Disregard, Thought I saw quotes in there. Quote Link to comment https://forums.phpfreaks.com/topic/39395-upload-image-problem/#findComment-190026 Share on other sites More sharing options...
fert Posted February 21, 2007 Share Posted February 21, 2007 use $_FILES Quote Link to comment https://forums.phpfreaks.com/topic/39395-upload-image-problem/#findComment-190028 Share on other sites More sharing options...
proctk Posted February 21, 2007 Author Share Posted February 21, 2007 what do you mean use $_file ''' I'm a rookie'' Quote Link to comment https://forums.phpfreaks.com/topic/39395-upload-image-problem/#findComment-190030 Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 Replace $HTTP_POST_FILES with $_FILES Quote Link to comment https://forums.phpfreaks.com/topic/39395-upload-image-problem/#findComment-190032 Share on other sites More sharing options...
proctk Posted February 21, 2007 Author Share Posted February 21, 2007 change made but set getting the same error posted initially Quote Link to comment https://forums.phpfreaks.com/topic/39395-upload-image-problem/#findComment-190054 Share on other sites More sharing options...
fert Posted February 21, 2007 Share Posted February 21, 2007 sure you sure the form has enctype="multipart/form-data" (I believe that's what it should be) Quote Link to comment https://forums.phpfreaks.com/topic/39395-upload-image-problem/#findComment-190057 Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 Hmm... Looks like this is actually possibly a simple one. Does the directory adImages exist, and does it have the proper permissions? Quote Link to comment https://forums.phpfreaks.com/topic/39395-upload-image-problem/#findComment-190060 Share on other sites More sharing options...
legohead6 Posted February 21, 2007 Share Posted February 21, 2007 i had a simular problem happen awhile back, i could not figure out what it was for the longest time, then gave up on that script, came back awhile later and relized that i had forgot a letter.... check and double and triple check it is spelled right Quote Link to comment https://forums.phpfreaks.com/topic/39395-upload-image-problem/#findComment-190114 Share on other sites More sharing options...
proctk Posted February 21, 2007 Author Share Posted February 21, 2007 I figured out the error issue its a path issue. I have another question I want to add to the files name = $user_name.-.file_name Quote Link to comment https://forums.phpfreaks.com/topic/39395-upload-image-problem/#findComment-190143 Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 Change $res = copy($HTTP_POST_FILES['file']['tmp_name'], $path . $HTTP_POST_FILES['file']['name']); to $res = copy($HTTP_POST_FILES['file']['tmp_name'], $path.$user_name."-".$HTTP_POST_FILES['file']['name']); Quote Link to comment https://forums.phpfreaks.com/topic/39395-upload-image-problem/#findComment-190147 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.