How to setup a Browse to Upload a Picture filed in a form?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sean Watkins
    New Member
    • Jan 2011
    • 48

    #1

    How to setup a Browse to Upload a Picture filed in a form?

    I want to place a browse... to upload a picture form on my website. I got everything I need from here

    With PHP, it is easy to upload files to the server.


    But I am having problem with the upload process. I have placed all three pages necessary on my server. Even named a folder "upload" within the server. But when I upload and run the test the file doesn't get uploaded correctly to my server. No image is in my upload folder. What do I need to do to make it work? I

    With PHP, it is easy to upload files to the server.


    It's a two to three part page code. It's located here on this link on the W3 Schools website. I would post what code I have, but I know the admins don't like it when you plain copy and paste the code. I never knew how to paste it correctly within the post.

    here is the file save code I have so far.

    Code:
    <?php
    if ((($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    || ($_FILES["file"]["type"] == "image/pjpeg"))
    && ($_FILES["file"]["size"] < 100000))
      {
      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 />";
    
        if (file_exists("http://www.penciledmemories.com/upload/" . $_FILES["file"]["name"]))
          {
          echo $_FILES["file"]["name"] . " already exists. ";
          }
        else
          {
          move_uploaded_file($_FILES["file"]["tmp_name"],
          "upload/" . $_FILES["file"]["name"]);
          echo "Stored in: " . "http://www.penciledmemories.com/upload/" . $_FILES["file"]["name"];
          }
        }
      }
    else
      {
      echo "Invalid file";
      }
    ?>
    the upload form can be found at http://www.penciledmemories.com/orderformbrowsere.html
    Last edited by Niheel; Jan 8 '11, 10:24 AM. Reason: You should always include your code and all relevant details in your question so Experts don't have to request it.
  • AutumnsDecay
    New Member
    • Mar 2008
    • 170

    #2
    Are you sure you have permissions set on the upload folder?

    Folders have what's known as 'CHMOD' permissions that control access to the folder from different user groups. If you're trying to run a script (public user group) but don't have the folder's permissions to allow 'WRITE' from 'PUBLIC / EVERYONE', it won't successfully upload.

    I tested it just now and I don't get a PHP error saying 'Permission Denied', so it may not be the issue, but it's worth a double check.

    Comment

    • Sean Watkins
      New Member
      • Jan 2011
      • 48

      #3
      Ok, how would I set the permissions to work? I didn't get that error either. But when I attempt to upload an image, it just doesn't appear in the folder I named "upload" on my server. Reason I created a folder named upload was because thats where W3's code defaulted to, thought it would make things easier. They link directly to /upload. I tried both to direct link to /upload and to http://www.mywebsite.com/upload, for some reason both seemed to have failed.

      Comment

      • AutumnsDecay
        New Member
        • Mar 2008
        • 170

        #4
        If you have FTP access to the directory, right click on the folder and click Properties (this will change depending on what FTP client you have).

        Once you're at the permissions window, set the folder to 777, which is everyone able to do anything with the folder and its contents. If there is no numeric value, just put a checkmark into every box (if there are check boxes).

        Comment

        • Sean Watkins
          New Member
          • Jan 2011
          • 48

          #5
          Ok, I will try that. Thanks

          Comment

          Working...