• 0

File upload being bent


Question

When I use a Webform with a php script to upload a file I have suddenly started to get the following error

Warning: Unable to open 'none' for reading: No such file or directory in /home/web/public_html/forum/admin/map.php on line 6

what does this mean?

the file/directory DOES exist and I've set the permissions :cry:

Link to comment
Share on other sites

12 answers to this question

Recommended Posts

  • 0

<?php

echo "Upload Exhibition layout map<br>";

if ($userfile) {

copy($userfile , "/home/web/public_html/forum/layoutphotos/$forum");

}

echo "<img src=/forum/layoutphotos/$forum>";

echo "<form enctype=multipart/form-data action=layoutmap.php?forum=$forum method=post>";

?>

<input type="hidden" name="MAX_FILE_SIZE" value="10000">

<input name="userfile" type="file">

<input type = submit value="upload">

</form>

<br><a href="index.php">Back to forum admin</a>

Link to comment
Share on other sites

  • 0

I presume it's the copy line that fails?

The only thing I can see that could be wrong is that that file doesn't exist. Are you sure it exists? How did you check? The if statement won't check if the file exists, it will just check the variable has a value. Try printing the variable to check it holds what you think it holds. Another method to ensure it's not just a missing file is to use the file_exists function before the copy:

&lt;?php
echo "Upload Exhibition layout map&lt;br&gt;";
if ($userfile) {
 ?if (file_exists($username))
 ? ?copy($userfile , "/home/web/public_html/forum/layoutphotos/$forum");
 ?else
 ? ?print "Error: File missing ($username)&lt;br /&gt;";
}
echo "&lt;img src=/forum/layoutphotos/$forum&gt;";
echo "&lt;form enctype=multipart/form-data action=layoutmap.php?forum=$forum method=post&gt;";
?&gt;
&lt;input type="hidden" name="MAX_FILE_SIZE" value="10000"&gt;
&lt;input name="userfile" type="file"&gt;
&lt;input type = submit value="upload"&gt;
&lt;/form&gt;
&lt;br&gt;&lt;a href="index.php"&gt;Back to forum admin&lt;/a&gt;

Also, check all permissions, not just on file but on the directory it's in too - and remember, it won't be you trying to access it, it will be the web server, so make sure all people can read it. chmod 644 should do it if it's a *nix server.

Link to comment
Share on other sites

  • 0

Error: File missing ()

It always gives that error message

permissions are set like this

mcug:/home/web/public_html/forum # ls -l

total 16

drwxrwxrwx 4 web users 4096 Jan 7 12:29 .

drwxr-xr-x 13 web users 4096 Jan 8 18:20 ..

drwxr-xr-x 2 web users 4096 Jan 6 17:24 admin

drwxrwxrwx 2 web users 4096 Jan 8 17:51 layoutphotos

mcug:/home/web/public_html/forum # cd layoutphotos

mcug:/home/web/public_html/forum/layoutphotos # ls -l

total 8

drwxrwxrwx 2 web users 4096 Jan 8 17:51 .

drwxrwxrwx 4 web users 4096 Jan 7 12:29 ..

-rwxrwxrwx 1 root root 0 Jan 8 17:51 1

mcug:/home/web/public_html/forum/layoutphotos #

and forum = 1 in this test

Link to comment
Share on other sites

  • 0

oh in your script you subbed $userfile for $username in some places...

I fixed this and get the following error instead now

Error: File missing (none)

Link to comment
Share on other sites

  • 0

Opps, sorry. A reado, if such a thing exists.

The "none" inside the brackets is it printing out the file name it has (assuming you changed my mistake there too, which it looks like you did). Is this what the file is supposed to be called? That file isn't in the layoutphotos directory - the only file I see there is called "1". By the looks of it, somewhere the file name you store in the $userfile variable gets lost or changed. How to you get this? Does this work on a different server? Is this variable passed from the user via a form? If so, try inserting the line $userfile = $_request['userfile']; after the echo line and before the first if statement. This will ensure the script gets the variable passed to it from a form, url-string or cookie.

BTW, the permissions look fine.

EDIT: Shouldn't there be a ; at the end of your sig? :D :rolleyes:

Link to comment
Share on other sites

  • 0

Rathamon, what version of PHP are you using? After PHP 4.2 register globals is turned off

by default, so the POST and GET variables have to be accessed through their associative

arrays.

try $_POST['userfile'] instead and see if that works.

Link to comment
Share on other sites

  • 0

PHP 4.1.2 the latest version that I've found to actually work properly with my apache setup....

Anyway I actually fixed the problem now, so thanks for the help :)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.