Connecting Tech Pros Worldwide Help | Site Map

Upload script error

brian.digipimp@gmail.com
Guest
 
Posts: n/a
#1: Nov 30 '05
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:

<html>
<head>
<title>Upload</title>
</head>
<body>
<?php


if(isset ($_POST['submit'])) {
if (move_uploaded_file ($_FILES['file']['tmp_name'],
"../upload/{$_FILES['file']['name']}")) {
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';
break;
case 2:
echo 'The files excees the MAX_FILE_SIZE setting in the HTML form';
break;
case 3:
echo 'The file was only partially uploaded';
break;
case 4:
echo 'No file was uploaded';
break;
}}}
?>
<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">
</form>
</body>
</html>

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?

Erwin Moller
Guest
 
Posts: n/a
#2: Nov 30 '05

re: Upload script error


brian.digipimp@gmail.com wrote:
[color=blue]
> 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:
>
> <html>
> <head>
> <title>Upload</title>
> </head>
> <body>
> <?php
>
>
> if(isset ($_POST['submit'])) {
> if (move_uploaded_file ($_FILES['file']['tmp_name'],
> "../upload/{$_FILES['file']['name']}")) {[/color]

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.

Regards,
Erwin Moller

brian.digipimp@gmail.com
Guest
 
Posts: n/a
#3: Nov 30 '05

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

Sean
Guest
 
Posts: n/a
#4: Nov 30 '05

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

Erwin Moller
Guest
 
Posts: n/a
#5: Dec 1 '05

re: Upload script error


Sean wrote:
[color=blue]
> 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[/color]

I would not advocate chmod 777 on any directory you want to keep for
yourself.
It opens the directory for read/write for everybody with access to the same
machine.
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
770

Regards,
Erwin Moller
Closed Thread