Results 1 to 7 of 7
  1. #1


    Member Since
    Mar 31, 2010
    Posts
    6
    PHP Upload Problem
    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...

  2. #2

    Raz0rEdge's Avatar
    Member Since
    Jul 17, 2009
    Location
    MA
    Posts
    8,612
    Specs:
    27" i7 iMac, 24" iMac, 13" Macbook Air, iPhone 6S, iPod Nano 7th GeniPad 3
    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

  3. #3


    Member Since
    Mar 31, 2010
    Posts
    6
    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?

  4. #4

    Raz0rEdge's Avatar
    Member Since
    Jul 17, 2009
    Location
    MA
    Posts
    8,612
    Specs:
    27" i7 iMac, 24" iMac, 13" Macbook Air, iPhone 6S, iPod Nano 7th GeniPad 3
    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

  5. #5


    Member Since
    Mar 31, 2010
    Posts
    6
    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.

  6. #6


    Member Since
    Mar 31, 2010
    Posts
    6
    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?

  7. #7


    Member Since
    Mar 31, 2010
    Posts
    6
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. iweb/upload problem
    By The Lump in forum Web Design and Hosting
    Replies: 1
    Last Post: 01-14-2009, 09:13 PM
  2. Real Player .php problem.
    By G3XOI in forum Switcher Hangout
    Replies: 0
    Last Post: 01-04-2009, 11:11 PM
  3. Dreamweaver upload problem
    By mag1313 in forum Web Design and Hosting
    Replies: 2
    Last Post: 03-25-2006, 08:47 AM
  4. PHP Temporary Upload Folder
    By Jetroza in forum Web Design and Hosting
    Replies: 0
    Last Post: 01-24-2004, 05:28 AM
  5. PHP problem
    By FancyPants in forum Web Design and Hosting
    Replies: 6
    Last Post: 01-20-2004, 04:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •