adam291086 Posted November 29, 2007 Share Posted November 29, 2007 I have this very simple upload script, but i always get my echoed error message and i dont know why. I have set the file permission to chmod 777. Any sugestions? <?php $target_path = "../adam/cycling/excel/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/ Share on other sites More sharing options...
The Little Guy Posted November 29, 2007 Share Posted November 29, 2007 does your form look similar to this: <form enctype="multipart/form-data" action="someaction.php" method="post"> Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402297 Share on other sites More sharing options...
adam291086 Posted November 30, 2007 Author Share Posted November 30, 2007 Yes it does Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402752 Share on other sites More sharing options...
adam291086 Posted November 30, 2007 Author Share Posted November 30, 2007 i thought i had this solved. The script seems to run but the file is not moved across. Can anyone suggest why. The folder storing the uploads is set to chmod 777 <?php $destination = "../adam/cycling/excel"; if ($_FILES["file"]["error"] >0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { move_uploaded_file ($_FILES["file"]["tmp_name"] , $destination . $_FILES["file"]["name"]); echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; echo $destination; } ?> and this is the form <html> <body><form action="uploader.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form></body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402772 Share on other sites More sharing options...
adam291086 Posted November 30, 2007 Author Share Posted November 30, 2007 after using error_reporting(E_ALL); i get the error messgae Warning: move_uploaded_file(adam/cycling/excel/Water lilies.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /homepages/12/d214897219/htdocs/adam/cycling/excel/uploader.php on line 10 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpFWcfC3' to 'adam/cycling/excel/Water lilies.jpg' in /homepages/12/d214897219/htdocs/adam/cycling/excel/uploader.php on line 10 but the directory does exsist Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402786 Share on other sites More sharing options...
MadTechie Posted November 30, 2007 Share Posted November 30, 2007 try $destination = dirname(__FILE__)."/../adam/cycling/excel"; Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402793 Share on other sites More sharing options...
adam291086 Posted November 30, 2007 Author Share Posted November 30, 2007 Still getting the same error, Warning: move_uploaded_file(/homepages/12/d214897219/htdocs/adam/cycling/excel/../adam/cycling/excelWater lilies.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /homepages/12/d214897219/htdocs/adam/cycling/excel/uploader.php on line 10 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpIpW0pa' to '/homepages/12/d214897219/htdocs/adam/cycling/excel/../adam/cycling/excelWater lilies.jpg' in /homepages/12/d214897219/htdocs/adam/cycling/excel/uploader.php on line 10 Upload: Water lilies.jpg Type: image/pjpeg Size: 81.830078125 Kb Temp file: /tmp/phpIpW0pa Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402795 Share on other sites More sharing options...
adam291086 Posted November 30, 2007 Author Share Posted November 30, 2007 thanks, played around with the directory and got it working. Cheers MadTechie Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402796 Share on other sites More sharing options...
adam291086 Posted November 30, 2007 Author Share Posted November 30, 2007 ok this is not solved, but sort of is. When i change the dirname to $path = "../adam/cycling/CSV/"; $destination= dirname($path); I get the error message Warning: move_uploaded_file(/adam/cyclingBlue hills.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /homepages/12/d214897219/htdocs/adam/cycling/excel/uploader.php on line 11 It seems to miss off the last part of $path, but when the directory name is $path = "../adam/cycling/"; $destination= dirname($path); it works fine. What is going on. The directory is there and spelled correctly. Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402804 Share on other sites More sharing options...
MadTechie Posted November 30, 2007 Share Posted November 30, 2007 $destination= dirname($path)."/"; note the filename are folder are concatenated into one Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402807 Share on other sites More sharing options...
adam291086 Posted November 30, 2007 Author Share Posted November 30, 2007 thanks That now has the "/" between the folder and the file. But its still missing part of the path i.e the CSV part $path = "../adam/cycling/excel/CSV/"; $destination= dirname($path)."/"; error Warning: move_uploaded_file(../adam/cycling/excel/Blue hills.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /homepages/12/d214897219/htdocs/adam/cycling/excel/uploader.php on line 11 Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402808 Share on other sites More sharing options...
adam291086 Posted November 30, 2007 Author Share Posted November 30, 2007 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402845 Share on other sites More sharing options...
MadTechie Posted November 30, 2007 Share Posted November 30, 2007 i'm kinda lost.. i assume you want this $path = dirname(__FILE__)."/CSV/"; $destination= $path; Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402852 Share on other sites More sharing options...
adam291086 Posted November 30, 2007 Author Share Posted November 30, 2007 well all i want to do is up load a file into the location $path = "../adam/cycling/excel/CSV/"; $destination= dirname($path."/"); When i can path to this address i get the error Warning: move_uploaded_file(../adam/cycling/excelWinter.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /homepages/12/d214897219/htdocs/adam/cycling/excel/uploader.php on line 11 When i have the path set as $path = "../adam/cycling/"; $destination= dirname($path."/"); everything works fine. Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402858 Share on other sites More sharing options...
MadTechie Posted November 30, 2007 Share Posted November 30, 2007 hummmm change $path = "../adam/cycling/excel/CSV/"; to $path = '../adam/cycling/excel/CSV/'; i think CSV maybe defined. so single quotes are needed in this case Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402859 Share on other sites More sharing options...
adam291086 Posted November 30, 2007 Author Share Posted November 30, 2007 Still getting the error Warning: move_uploaded_file(../adam/cycling/excelWinter.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /homepages/12/d214897219/htdocs/adam/cycling/excel/uploader.php on line 11 If you look at the error its missing some of the file directory (../adam/cycling/excelWinter.jpg) this should have (../adam/cycling/excel/CSV/Winter.jpg) Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402863 Share on other sites More sharing options...
MadTechie Posted November 30, 2007 Share Posted November 30, 2007 can you post your lastest code Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402866 Share on other sites More sharing options...
adam291086 Posted November 30, 2007 Author Share Posted November 30, 2007 This is the upload <?php error_reporting(E_ALL); $path = '../adam/cycling/excel/CSV/'; $destination= dirname($path."/"); if ($_FILES["file"]["error"] >0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { move_uploaded_file ($_FILES["file"]["tmp_name"] , $destination. $_FILES["file"]["name"]); echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; } ?> and this is the form <html> <body><form action="uploader.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form></body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402870 Share on other sites More sharing options...
MadTechie Posted November 30, 2007 Share Posted November 30, 2007 <?php error_reporting(E_ALL); $path = '../adam/cycling/excel/CSV/'; $destination= $path; //<--changed if ($_FILES["file"]["error"] >0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { move_uploaded_file ($_FILES["file"]["tmp_name"] , $destination. $_FILES["file"]["name"]); echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402874 Share on other sites More sharing options...
MadTechie Posted November 30, 2007 Share Posted November 30, 2007 OR <?php error_reporting(E_ALL); $path = dirname(__FILE__)."/CSV/"; $destination= $path; if ($_FILES["file"]["error"] >0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { move_uploaded_file ($_FILES["file"]["tmp_name"] , $destination. $_FILES["file"]["name"]); echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; } ?> i'm kinda lost.. i assume you want this $path = dirname(__FILE__)."/CSV/"; $destination= $path; basically your using dirname incorrectly another option $path = '../adam/cycling/excel/CSV/'; $destination= realpath($path); Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402875 Share on other sites More sharing options...
adam291086 Posted November 30, 2007 Author Share Posted November 30, 2007 second one worked. does $path = dirname(__FILE__)."/ means $path = same location as the php file being run? Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402877 Share on other sites More sharing options...
MadTechie Posted November 30, 2007 Share Posted November 30, 2007 the directory of the file current file being run.. SO.. $path = dirname('../adam/cycling/excel/CSV/'); really means "../adam/cycling/excel/" Quote Link to comment https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402884 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.