ratcateme Posted January 15, 2008 Share Posted January 15, 2008 I have a script with this line. move_uploaded_file($_FILES['file']['tmp_name'],'letters/'.$id.'.html'); i can output the id number file and the error shows it knows the id number my letters directory is 777 but i get this error Warning: move_uploaded_file(letters/4.html) [function.move-uploaded-file]: failed to open stream: No such file or directory in /var/www/html/news.inc on line 34 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php7lQTBL' to 'letters/4.html' in /var/www/html/news.inc on line 34 i have tried to use full paths and other things but nothing worked Please help Thanks Scott. Quote Link to comment https://forums.phpfreaks.com/topic/86092-solved-move_uploaded_file-errors/ Share on other sites More sharing options...
toplay Posted January 15, 2008 Share Posted January 15, 2008 Check that it uploaded first before trying to move it: http://us.php.net/manual/en/function.is-uploaded-file.php See: http://us.php.net/manual/en/features.file-upload.php Quote Link to comment https://forums.phpfreaks.com/topic/86092-solved-move_uploaded_file-errors/#findComment-439597 Share on other sites More sharing options...
ratcateme Posted January 15, 2008 Author Share Posted January 15, 2008 i changed my code to if(is_uploaded_file($_FILES['file']['tmp_name'])){ move_uploaded_file($_FILES['file']['tmp_name'],'letters/'.$id.'.html'); }else{ echo 'Not uploaded'; } but i got the same error so my is_uploaded_file returns true my $_FILES array is Array ( [file] => Array ( [name] => Untitled-1.html [type] => text/html [tmp_name] => /tmp/phpAmS6tC [error] => 0 [size] => 344 ) ) Thanks Scott. Quote Link to comment https://forums.phpfreaks.com/topic/86092-solved-move_uploaded_file-errors/#findComment-439602 Share on other sites More sharing options...
toplay Posted January 15, 2008 Share Posted January 15, 2008 I don't know your directory structure, but if letters is in the current directory the script is in you might want to use: './letters/' . $id . '.html' or start the filename with a letter: './letters/a' . $id . '.html' Quote Link to comment https://forums.phpfreaks.com/topic/86092-solved-move_uploaded_file-errors/#findComment-439606 Share on other sites More sharing options...
ratcateme Posted January 15, 2008 Author Share Posted January 15, 2008 thanks for the help my letters directory is in the same as my script i tried your suggestions changing my code to move_uploaded_file($_FILES['file']['tmp_name'],'./letters/'.$id.'.html'); and to move_uploaded_file($_FILES['file']['tmp_name'],'letters/a'.$id.'.html'); and move_uploaded_file($_FILES['file']['tmp_name'],'./letters/a'.$id.'.html'); But got nothing i have an image upload script in the same directory that uploads file to a different directory and it works fine Scott. Quote Link to comment https://forums.phpfreaks.com/topic/86092-solved-move_uploaded_file-errors/#findComment-439610 Share on other sites More sharing options...
ratcateme Posted January 15, 2008 Author Share Posted January 15, 2008 i put this in my script before the move_uploaded_file $last_line = system('ls -Z /tmp', $retval); echo $retval; echo $last_line; echo '</pre>'; and got this -rw------- apache apache phpStXMhI 0-rw------- apache apache phpStXMhI the file name is the same as the one in the error message Scott. Quote Link to comment https://forums.phpfreaks.com/topic/86092-solved-move_uploaded_file-errors/#findComment-439611 Share on other sites More sharing options...
priti Posted January 15, 2008 Share Posted January 15, 2008 hi, please give write access to your folder.Check weather user which is listed there can write the file in that folder or not? Regards Quote Link to comment https://forums.phpfreaks.com/topic/86092-solved-move_uploaded_file-errors/#findComment-439626 Share on other sites More sharing options...
ratcateme Posted January 15, 2008 Author Share Posted January 15, 2008 priti i used "ls -Z" and the letters line says drwxrwxrwx root root root:object_r:httpd_sys_content_t:s0 letters so the directory is world writable i chmod it to 777 yesterday Scott. Quote Link to comment https://forums.phpfreaks.com/topic/86092-solved-move_uploaded_file-errors/#findComment-439633 Share on other sites More sharing options...
priti Posted January 15, 2008 Share Posted January 15, 2008 priti i used "ls -Z" and the letters line says drwxrwxrwx root root root:object_r:httpd_sys_content_t:s0 letters so the directory is world writable i chmod it to 777 yesterday Scott. oops sorry , then please try $copy_to_file='letters/a'.$id.'html'; move_uploaded_file($_FILES['file']['tmp_name'],$copy_to_file); Regards Quote Link to comment https://forums.phpfreaks.com/topic/86092-solved-move_uploaded_file-errors/#findComment-439648 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 you need to define the absolute directory path try something like this add this to the top of your code as it defines the destination $path = dirname(__FILE__)."/letters/"; then change move_uploaded_file($_FILES['file']['tmp_name'],'letters/'.$id.'.html'); to move_uploaded_file($_FILES['file']['tmp_name'],$path.$id.'.html'); if that doesn't work show me your whole code and the errors Quote Link to comment https://forums.phpfreaks.com/topic/86092-solved-move_uploaded_file-errors/#findComment-439651 Share on other sites More sharing options...
ratcateme Posted January 15, 2008 Author Share Posted January 15, 2008 Thanks Adam That worked i didn't wont to use full paths because i am planing to move to a hosting company but dirname(__FILE__) works perfectly Thanks Scott. Quote Link to comment https://forums.phpfreaks.com/topic/86092-solved-move_uploaded_file-errors/#findComment-439663 Share on other sites More sharing options...
adam291086 Posted January 15, 2008 Share Posted January 15, 2008 yeah dirname(__FILE__) will return the root destination. Quote Link to comment https://forums.phpfreaks.com/topic/86092-solved-move_uploaded_file-errors/#findComment-439664 Share on other sites More sharing options...
ratcateme Posted January 15, 2008 Author Share Posted January 15, 2008 I just worked out that dirname(__FILE__) can actually fix a few things on my site Quote Link to comment https://forums.phpfreaks.com/topic/86092-solved-move_uploaded_file-errors/#findComment-439667 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.