Upload script error

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
So I wrote this upload script and I keep getting errors and can't get
it to work. I'm running ubuntu linux and here is my code:


    if(isset ($_POST['submit'])) {
    if (move_uploaded_file ($_FILES['file']['tmp_name'],
"../upload/")) {
    echo 'Your file has been uploaded';}
else {
    echo 'Your file could not be uploaded because: ';
switch ($_FILES['file']['error']) {
case 1:
    echo 'The file exceeds the upload_max_filesize setting in php.ini';
case 2:
    echo 'The files excees the MAX_FILE_SIZE setting in the HTML form';
case 3:
    echo 'The file was only partially uploaded';
case 4:
    echo 'No file was uploaded';
<form action="upload.php" enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE="50000">
<input type="file" name="file">
<input type="submit" name="submit" value="Upload">

I keep getting 2 errors:

Warning: move_uploaded_file(../upload/whatever.txt): failed to open
stream: No such file or directory in /var/www/upload.php on line 10

Warning: move_uploaded_file(): Unable to move '/tmp/phpUztFu8' to
'../upload/whatever.txt' in /var/www/upload.php on line 10

What does this mean and how do I fix it?

Re: Upload script error

brian.digipimp@gmail.com wrote:

Quoted text here. Click to load it

You should put a real path to a directory here instead of a relative one.

And make sure the user that runs as PHP (often apache, nobody, or www-data)  
has write-right in that directory.

Good luck.

Erwin Moller

Re: Upload script error

Ok, well theres the problem then... I'm new to this stuff and I dont
really have any idea how to change directory permissoins. How do I
check the user and the permissoins? I'm running linux btw

Re: Upload script error

ls -l > will print out the directory list with permissions, owner group
and size etc....

chmod 777 folder_name > this will allow the folder to be written to

chown owner:group folder_name > this will change the owner and group of
the folder name

Re: Upload script error

Sean wrote:

Quoted text here. Click to load it

I would not advocate chmod 777 on any directory you want to keep for  
It opens the directory for read/write for everybody with access to the same  
In a shared hosting environment this is not very safe..

It may be better to have a little chit-chat with your provider and ask him  
for a solution with an extra group that contains the original user and  
www-data (or whatever apache is running as).
Then change to 774 <dirname>
or even

Erwin Moller

Site Timeline