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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Mar 2008
    Posts
    118
    Thanks
    3
    Thanked 9 Times in 9 Posts

    PHP, IIS 7, File Upload Problems

    Hi,

    I recently started hosting my own website on my computer, instead of a third party hosting site. I set up the databases, included PHP and everything was running fine under IIS 7 on Vista. However, I have a file upload script that no longer works on my site. the code stayed the same from the other hosting service and on my computer. So I am basically asking whether there a setting or something that needs to be changed in order to allow file upload. In my fileupload.php code, it returns "Invalid File" when the criteria for the image is not met, and every time I try to upload a file in the criteria, I receive that error.

    Here is my code:

    PHP Code:
    <form accept-charset="UNKNOWN" action="fileupload.php" method="post" enctype="multipart/form-data">
    <
    label for="file">Picture Filename:</label>
    <
    input type="file" name="file" id="file" /> 
    <
    br />
    <
    input type="submit" name="submit" value="Submit" />
    </
    form


    fileupload.php:


    PHP Code:
    <?php
    if ((($_FILES["file"]["type"] == "image/gif")
    || (
    $_FILES["file"]["type"] == "image/jpeg")
    || (
    $_FILES["file"]["type"] == "image/pjpeg"))
    && (
    $_FILES["file"]["size"] < 850000))
      {
      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("uploads/" $_FILES["file"]["name"]))
          {
          echo 
    $_FILES["file"]["name"] . " already exists. ";
          }
        else
          {
          
    move_uploaded_file($_FILES["file"]["tmp_name"],
          
    "uploads/" $_FILES["file"]["name"]);
          echo 
    "Stored in: " "uploads/" $_FILES["file"]["name"];
          }
        }
      }
    else
      {
      echo 
    "Invalid file";
      }
    Last edited by peteyb383; 03-02-2008 at 11:34 PM.

  • #2
    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
    Are you getting any errors? You may have to set the permissions on the folder that you are trying to upload to.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    Regular Coder
    Join Date
    Mar 2008
    Posts
    118
    Thanks
    3
    Thanked 9 Times in 9 Posts
    I'm not getting any errors surprisingly. It's just skipping down to the "else statement" as if the image does not fit the criteria.

    Also, I have shared the uploads folder with "IIS_IUSRS" making it a co-owner. I am a little unfamiliar with Vista but to my knowledge making IIS a co owner give it all privileges to the directory.

    The php.ini file I have allows file uploads with a max limit of 2MB, which I am well under, It just seems weird that the same code works with my other host, but not when I myself host my site.

    Thanks for any/anymore input provided.

  • #4
    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
    I know you aren't using wordpress but the tips here might help.
    http://joseph.randomnetworks.com/arc...oads-with-iis/
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    what do you see when you
    PHP Code:
    <?php print_r($_FILES);?>
    ?
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #6
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,039
    Thanks
    2
    Thanked 316 Times in 308 Posts
    I keep seeing that same crappy upload code. Where are people copying that from?

    It does not check the ['error'] element until after it checks the ['type'] and ['size']. People, if there is an error, the type and size will be empty and testing them will fail. You must check for errors before you ever touch any of the data.

    Also, by combining all the type and size testing into one conditional statement and one error message, you will never know which test failed.

    The error message, which is just echo "Invalid file"; now, needs to output a meaningful message as to what exactly was wrong and what the value was, for example echo $_FILES["file"]["type"]; as part of the error so that you know what was actually received.

    It is likely that file uploading is disabled on your server or the temp location for uploading files to does not exist or does not have the proper permissions. You need to check all the runtime values related to uploads using a phpinfo() statement.

    I won't even suggest turning on full php error reporting and then checking your web server log file because you probably did those troubleshooting steps before posting your problem in a forum.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #7
    Regular Coder
    Join Date
    Mar 2008
    Posts
    118
    Thanks
    3
    Thanked 9 Times in 9 Posts
    what do you see when you
    PHP Code:
    <?php print_r($_FILES);?>
    ?

    Parse error: syntax error, unexpected T_STRING in C:\inetpub\wwwroot\fileupload.php on line 7


    I get the above error...
    Last edited by peteyb383; 03-03-2008 at 12:32 PM.

  • #8
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,039
    Thanks
    2
    Thanked 316 Times in 308 Posts
    The posted code does not produce that error. In fact, the posted code does not produce any fatal php parse errors.

    You would need to post the actual code that caused that error to get help with what is causing it.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Posting Permissions

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