Using PHP to upload... possible permissions problem, or something else?

Hey all. I’ve been working my way through learning some php, and while trying to implement one of the examples in the book I’m using have run into a snag. Basically, the code for the line that’s causing problems is:



if (move_uploaded_file ($_FILES['thefile']['tmp_name'], "../uploads/{$Files['thefile']['name']}")) {
	print '<p>Your file has been uploaded.</p>';


However, when I upload my page to my server and try to run it, I get this error:



Warning: move_uploaded_file(../uploads/) [function.move-uploaded-file]: failed to open stream: Is a directory in /home/my_name/public_html/upload_file.php on line 16

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php35s8a3' to '../uploads/' in /home/my_name/public_html/upload_file.php on line 16



The php file is in the web root directory (public_html), and the folder uploads, with permissions set to 0777 is outside that directory, in the my_name folder which contains both public_html and uploads (per recommendation of the book I’m using).

It seems to not be able to see the directory. I tried this also putting the upload directory in a folder that was in public_html, but got the same error.
Any thoughts?

It looks as if it is trying to move the file to /uploads, not /uploads/filename.

Try not having the [‘the_file’][‘name’] in the string, but append it using .

Hm… that didn’t seem to change anything. Thanks though!

Do you have access to your root server? Can you use PutTy to get in? It may be a CHOWN problem.

I do (I think). I have access to the folder above my public_html folder.

CHOWN? I’ve used chmod before, but not chown. Is it another permissions-related thing? I am also a very very beginner UNIX user.

Cool, when I say access to your server, I mean root access to the server itself using a command prompt interface. Not so much the folders.

What type of hosting do you have? Is it shared, or do you have your own server or even a Virtual Private Server?

Also, this is all about CHOWN

Damn, sorry for yet another post. But I MUST ADVICE, if you don’t know what you’re doing, don’t go messing around with a CHOWN command. Hell, or any other command for that matter either. You may need to ask your host to CHOWN the proper file, that is, if that’s even the problem here.

:slight_smile: Thanks for the advice. It’s a shared hosting solution, and yes, I can get a command prompt on the server.

Ok, so I’m an idiot.

It seems that where I have randomly decided to use the variable $files, it ought to have been $S_FILES. It’s funny, I went over the source code comparing it to mine a bunch of times, and didn’t catch that I had made that error.

Thanks for the help, though!