Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/86092-solved-move_uploaded_file-errors/
Share on other sites

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.

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. 

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.

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

 

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

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.