New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
Web Design and Hosting Creating sites, scripting, and hosting discussions.

PHP Upload Problem


Post Reply New Thread Subscribe

 
Thread Tools
d2lil

 
Member Since: Mar 31, 2010
Posts: 6
d2lil is on a distinguished road

d2lil is offline
I am fairly familiar with PHP and have just recently got Apache and MySQL to work on Snow Leopard. My idea is to create a sort of "digital file cabinet" to manage PDFs for my home use. However, I have ran into a snag...

In researching how to upload files in PHP, I came across the following w3 website: PHP File Upload

After copying their exact code (minus the restriction part), my code is the following:

Code:
<?php	
  //upload_file.php
	
  if($_FILES["file"]["error"] > 0) 
  {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
  }
  else
  {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp File: " . $_FILES["file"]["tmp_name"] . "<br />";
		
    move_uploaded_file($_FILES["file"]["tmp_name"],
    "upload/" . $_FILES["file"]["name"]);
    echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  }	
?>
After I upload a file, my browser returns the following:

Upload: test.png
Type: image/png
Size: 92.7666015625 Kb
Temp File: /private/var/tmp/php6ZY6Ad
Warning: move_uploaded_file(upload/test.png): failed to open stream: Permission denied in /Users/jg/Sites/development/testing/upload_file.php on line 14 Warning: move_uploaded_file(): Unable to move '/private/var/tmp/php6ZY6Ad' to 'upload/test.png' in /Users/jg/Sites/development/testing/upload_file.php on line 14 Stored in: upload/test.png

I've hunted around on the web...but no one seems to have a the same problem...
QUOTE Thanks
Raz0rEdge

 
Raz0rEdge's Avatar
 
Member Since: Jul 17, 2009
Location: MA
Posts: 7,501
Raz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant future
Mac Specs: 27" i7 iMac, 24" iMac, 13" Macbook Air, iPhone 5 & 5S, iPod Nano 7th Gen, iPad 2 16GB WiFi, iPad 3

Raz0rEdge is offline
What are the permissions of the 'upload' directory? You'll need to give the web server access to it before it can move files into it..

Regards
QUOTE Thanks
d2lil

 
Member Since: Mar 31, 2010
Posts: 6
d2lil is on a distinguished road

d2lil is offline
Duh! I went to "Get Info" on the upload folder and Everyone was set to "Read only". Once I changed Everyone to "Read & Write", it worked! Thanks!

Now this shouldn't pose any kind of security issue since I'm just using this within my own network should it?
QUOTE Thanks
Raz0rEdge

 
Raz0rEdge's Avatar
 
Member Since: Jul 17, 2009
Location: MA
Posts: 7,501
Raz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant futureRaz0rEdge has a brilliant future
Mac Specs: 27" i7 iMac, 24" iMac, 13" Macbook Air, iPhone 5 & 5S, iPod Nano 7th Gen, iPad 2 16GB WiFi, iPad 3

Raz0rEdge is offline
That's correct..you shouldn't have any security issues with this since you are testing everything locally..

If you are paranoid..you can always figure out under what user the web server runs as and then explicitly give that user read&write access..

Regards
QUOTE Thanks
d2lil

 
Member Since: Mar 31, 2010
Posts: 6
d2lil is on a distinguished road

d2lil is offline
Well...I'm not exactly paranoid. How would I go about finding out what "user" the web server runs under? Would it be root? I know you have to use sudo to start/restart Apache.
QUOTE Thanks
d2lil

 
Member Since: Mar 31, 2010
Posts: 6
d2lil is on a distinguished road

d2lil is offline
Well I think I know the "user" now, but I just don't know how to add it. I looked at the permissions of the files that I uploaded using my script and user "_www" has "Read & Write" access and user "wheel" has "Read Only". So I'm thinking that is what I need to grant permissions to my "upload" folder. But when I click the (+) to add a user to the permissions list "_www" isn't there. Maybe a Terminal command?
QUOTE Thanks
d2lil

 
Member Since: Mar 31, 2010
Posts: 6
d2lil is on a distinguished road

d2lil is offline
Alright, I have found my own answer but I will share just in case someone else would like to know how I did it.

_www is the user and group that Apache runs under in Mac OS. I found this discussion which talks about how to grant permissions to that user.

It suggests two ways but the easiest is to use a free program called BatChmod.app (it can be found here).

BatChmod allows you to select a directory or file and grant permissions to a whole slew of hidden users within the MacOS System and _www is one of them.
QUOTE Thanks

Post Reply New Thread Subscribe


« Secure server solutions for clients | Easy iWeb Publisher »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
I have a mind boggling iPhone 3g sync problem sedouard iOS and Apps 4 04-03-2009 02:54 AM
Problem displaying text OS X keep.it.up OS X - Operating System 1 03-01-2009 08:10 PM
verizon fios router disconnecting on upload every time jkern822 Internet, Networking, and Wireless 2 02-11-2009 12:51 PM
G5 Video problem WilliS Apple Desktops 3 05-05-2004 09:16 AM
PHP problem FancyPants Web Design and Hosting 6 01-20-2004 04:09 PM

All times are GMT -4. The time now is 06:31 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?