Forum Moderators: coopster

Message Too Old, No Replies

Problem with uploading files

Problem with uploading files

         

urms

9:35 am on Apr 17, 2009 (gmt 0)

10+ Year Member



Hi,

I have a very weird problem with uploading files using a php script.

It returns error #7:

UPLOAD_ERR_CANT_WRITE Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0.

I have checked everything: target directory permissions, availability of temp directory, maximum allowed file size and post size limit. Everything is fine, what's more when I use a web proxy I can successfully upload the same files through it onto the server. I asked my colleague who is far away in another network to check it and he also can't upload files while the hosting support rep can do it successfully.

Please advise how to resolve it or at least where to start from...

Thanks

henry0

11:29 am on Apr 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looks like a permission problem, not the target dir permission but your own permission level as a user

urms

2:06 pm on Apr 17, 2009 (gmt 0)

10+ Year Member



How can that be? I'm not logged in. I was testing with a very simple script which had nothing but the form and a very simple script for getting the file

rocknbil

4:18 pm on Apr 17, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's got nothing to do with a login in. Henry0 is talking about server user permissions. I don't know that it applies though, because any user from the web is the same user, "apache" (if it's an apache server.)

I asked my colleague who is far away in another network to check it and he also can't upload files while the hosting support rep can do it successfully.

Something is definately astray here. So this rep is using YOUR script? This is not a case of "it works in the sample script provided, not in your version?"

An anonymous user is an anonymous user. The only difference is the browser, IP, and network.

Start with the original error:

Failed to write file to disk.

There are a number of reasons you "can't write to disk." Some obvious ones:
- You're writing to a directory that doesn't exist
- you're writing to a directory outside root, and don't have permissions to do so (an apache user can't do this, but a root user can.)
- you're writing to a directory for which permissions OR ownership are not set.

How can these occur?

Script is in /home/domainname.com

write to => home/domainname.com/uploads

See the error? If you start from domainname.com, this is asking to write to /home/domainname.com/home/domainname.com/uploads, which doesn't exist. A single typo like this can cause all the grief you need to start sprouting gray hair.

The way I like to do this:

Create a variable named "$debug" at the top.

Throughout your script drop it in key points:

$debug .= " entering script ";
......
$debug .= " uploading file ";
......
$debug .= " file uploaded, moving to $move_to ";
......
$debug .= " file moved, returning response ";
......
$debug .= " done ";

echo "<!-- $debug -->";

This allows it to run normally and points to exactly where it's going wrong, and why.

Returning to the original quote - why can your rep do it - try a different browser. It could be something on your end, a virus, who knows?

One last thing, you ARE using enctype multipart/form-data on the form, right? (Shouldn't cause this, but just the same . . . )