Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: w3c File Upload

  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts

    w3c File Upload

    Ok I read the post rafiki made and didn't understand it because I'm very new at php and I only know what I read on w3c from tutorial 1 to uploading files. I did read everything and I didn't just do a cheap copy and paste of this script.

    http://groogstestpages.freehostia.com/upload.php
    try uploading a gif or jpeg

    first page
    Code:
    <html>
    <head>
    <title>
    Upload Test
    </title>
    <link href="upload.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <div id="wrapper">
      <form action="upload_file.php" method="POST" enctype="multipart/form-data">
        <label for="file">File:</label>
        <input type="file" name="file" id="file">
        <input type="submit" name="submit" value="Upload">
      </form>
    </div>
    </body>
    </html>
    Second Page
    Code:
    <html>
    <head>
    <title>
    Upload Test Complete
    </title>
    <link href="upload.css" rel="stylesheet" type="text/css">
    </head>
    <body>
    <div id="wrapper">
      <?php
        if (($_FILES['file']['type'] == "image/gif")
        || ($_FILES['file']['type'] == "image/pjpeg"))
        {
          if ($_FILES['file']['error'] > 0){
            echo "Error" . $_FILES['file']['error'] . "<br />";
          }
          else
          {
            echo "Name: " . $_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($_FILE['file']['tmp-name'], "uploads/" . $_FILES['file']['name']);
            echo "stored in: " . "uploads/" . $_FILES['file']['name'];
          }
        }
        else
        {
          echo "invalid file<br>";
          var_dump($_FILES);
        }
      ?>
    </div>
    </body>
    </html>
    I'm hoping you guys can see something here because the guys at php freaks couldn't figure it out (some php gurus they are!). I do have a folder set up named uploads in the same directory as this file so that's all set up.

  • #2
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    I dont see anything wrong with your code either, I'm thinking it might have something to do with your server setup. I'm not sure whether you need to have safe mode disabled for $_FILE transactions. If your willing, make a file that is completely empty save for:

    Code:
    <?php
    phpinfo();
    ?>
    Save it, upload it, and link it here so we can see if it is something with your server.

    From the way your code is acting, its failing here:

    if (($_FILES['file']['type'] == "image/gif") || ($_FILES['file']['type'] == "image/pjpeg"))

    thus making me check your form but that is correct. So I am clueless save for server error.

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by thesavior View Post
    From the way your code is acting, its failing here:

    if (($_FILES['file']['type'] == "image/gif") || ($_FILES['file']['type'] == "image/pjpeg"))
    That's exactly what I thought. It makes sense.

    Here's that page: http://groogstestpages.freehostia.com/phpinfo.php

  • #4
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    the problem is in your html not your php. Sometimes it pays to cut & paste - you typoed

    If the code you posted here is the same as you the code you posted to the other forum I'm not suprised they couldnt spot the problem. The form you have posted here is correct! But the form on your site has this: encypte="multipart/form-data"

  • #5
    New Coder
    Join Date
    Jun 2007
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I did make that change but I must not have uploaded the file. It does work now but the image doesn't appear to be uploading.

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    You should look back at the thread you got the code from. Its been developed further and should now work. See if the changes made make yours work.
    File Upload
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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