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

**URL:** <https://boards.straightdope.com/t/using-php-to-upload-possible-permissions-problem-or-something-else/371950>\
**Category:** Factual Questions\
**Created:** [September 8, 2006, 5:55pm UTC](https://boards.straightdope.com/t/using-php-to-upload-possible-permissions-problem-or-something-else/371950 "2006-09-08T17:55:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eonwe](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/eonwe/32/240_2.png) [@Eonwe](https://boards.straightdope.com/u/Eonwe)\
**Post date:** [September 8, 2006, 5:55pm UTC](https://boards.straightdope.com/t/using-php-to-upload-possible-permissions-problem-or-something-else/371950/1 "2006-09-08T17:55:33Z")

</div>

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:

```auto

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:

```auto

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?

---

<div class="post-metadata">

**Author:** ![abla512](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@abla512](https://boards.straightdope.com/u/abla512)\
**Post date:** [September 9, 2006, 9:34am UTC](https://boards.straightdope.com/t/using-php-to-upload-possible-permissions-problem-or-something-else/371950/2 "2006-09-09T09:34:52Z")

</div>

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 .

---

<div class="post-metadata">

**Author:** ![Eonwe](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/eonwe/32/240_2.png) [@Eonwe](https://boards.straightdope.com/u/Eonwe)\
**Post date:** [September 11, 2006, 1:24pm UTC](https://boards.straightdope.com/t/using-php-to-upload-possible-permissions-problem-or-something-else/371950/3 "2006-09-11T13:24:43Z")

</div>

[QUOTE=abla512]  
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 .  
[/QUOTE]

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

---

<div class="post-metadata">

**Author:** ![diggleblop](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@diggleblop](https://boards.straightdope.com/u/diggleblop)\
**Post date:** [September 11, 2006, 1:53pm UTC](https://boards.straightdope.com/t/using-php-to-upload-possible-permissions-problem-or-something-else/371950/4 "2006-09-11T13:53:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Eonwe](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/eonwe/32/240_2.png) [@Eonwe](https://boards.straightdope.com/u/Eonwe)\
**Post date:** [September 11, 2006, 2:09pm UTC](https://boards.straightdope.com/t/using-php-to-upload-possible-permissions-problem-or-something-else/371950/5 "2006-09-11T14:09:40Z")

</div>

[QUOTE=diggleblop]  
Do you have access to your root server? Can you use PutTy to get in? It may be a CHOWN problem.  
[/QUOTE]

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.

---

<div class="post-metadata">

**Author:** ![diggleblop](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@diggleblop](https://boards.straightdope.com/u/diggleblop)\
**Post date:** [September 11, 2006, 2:15pm UTC](https://boards.straightdope.com/t/using-php-to-upload-possible-permissions-problem-or-something-else/371950/6 "2006-09-11T14:15:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![diggleblop](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@diggleblop](https://boards.straightdope.com/u/diggleblop)\
**Post date:** [September 11, 2006, 2:16pm UTC](https://boards.straightdope.com/t/using-php-to-upload-possible-permissions-problem-or-something-else/371950/7 "2006-09-11T14:16:54Z")

</div>

Also, this is all about CHOWN

> **[chown](https://en.wikipedia.org/wiki/Chown)**
>
> The command .mw-parser-output .monospaced{font-family:monospace,monospace}chown /ˈtʃoʊn/, an abbreviation of change owner, is used on Unix and Unix-like operating systems to change the owner of file system files, directories. Unprivileged (regular) users who wish to change the group membership of a file that they own may use chgrp.
> The ownership of any file in the system may only be altered by a super-user. A user cannot give away ownership of a file, even when the user owns it. Similarly, only ...

---

<div class="post-metadata">

**Author:** ![diggleblop](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@diggleblop](https://boards.straightdope.com/u/diggleblop)\
**Post date:** [September 11, 2006, 2:18pm UTC](https://boards.straightdope.com/t/using-php-to-upload-possible-permissions-problem-or-something-else/371950/8 "2006-09-11T14:18:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Eonwe](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/eonwe/32/240_2.png) [@Eonwe](https://boards.straightdope.com/u/Eonwe)\
**Post date:** [September 11, 2006, 2:27pm UTC](https://boards.straightdope.com/t/using-php-to-upload-possible-permissions-problem-or-something-else/371950/9 "2006-09-11T14:27:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Eonwe](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/eonwe/32/240_2.png) [@Eonwe](https://boards.straightdope.com/u/Eonwe)\
**Post date:** [September 11, 2006, 6:33pm UTC](https://boards.straightdope.com/t/using-php-to-upload-possible-permissions-problem-or-something-else/371950/10 "2006-09-11T18:33:22Z")

</div>

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!
