File uploads not working on a Windows server using PHP 5

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rveetil
    New Member
    • Nov 2008
    • 2

    File uploads not working on a Windows server using PHP 5

    Hi
    I'm also struggling with a simple upload. My settings are Tomcat 6.0.14, PHP 5.2.6 on Windows XP. I tried PHP 5.0.0 and 5.2.5 versions also,

    The script is below

    [CODE=html]<form enctype="multip art/form-data" action="upload. php" method="POST" >
    <input type="hidden" name="MAX_FILE_ SIZE" value="300000" />
    <input type="text" name="comment" value="" />
    Send this file: <input name="userfile" type="file" />
    <input type="submit" name="submit" value="Send File" />
    </form>[/CODE]

    File upload.php
    [CODE=php]
    <?php

    $sub= $_POST['submit'];
    $com= $_POST['comment'];

    $uploaddir = '/uploads/';
    $uploadfile = $uploaddir . basename($_FILE S['userfile']['name']);
    echo 'Submit is '. $sub;
    echo 'Comment is '.$com;
    //phpinfo();
    echo $uploadfile ;

    echo '<pre>';
    //if (move_uploaded_ file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    // echo "File is valid, and was successfully uploaded.\n";
    //} else {
    // echo "Possible file upload attack!\n";
    //}

    echo 'Here is some more debugging info:';
    print_r($_FILES );

    print "</pre>";

    ?>
    [/CODE]

    When I load a text file, the response is quick but no POST variable is registered. The output is
    Code:
    Submit is Comment is /uploads/
    Here is some more debugging info:Array
    (
    )

    When I load a JPG file, it takes a long time (around 10min) to get back and a page error is showing.

    The JPG file is only 80KB size. The php.ini file have the following settings
    Code:
    file_uploads = On
    upload_max_filesize = 10M
    upload_tmp_dir =
    I've created the TMPDIR env variable pointing to an existing dir c:\temp

    The uploads directory is created in the folder where the files are created. Full control on the directories are given to all users.

    Any help will be appreciated.
    Last edited by Atli; Nov 3 '08, 04:21 AM. Reason: Added [code] tags
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi rveetil. Welcome to Bytes!

    I have moved your post into it's own thread to avoid hijacking the thread you originally posted it into.

    I also added [code] tags to your post to make it easier to read.

    Please remember to use [code] tags when posting code examples.
    (See How to ask a question)

    Thank you.
    Moderator

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      As to your question, I have two suggestions.

      First, I remember setting up a Windows server once (before I stopped trying to shoot myself in the leg and moved on to Linux).
      The only way I managed to get the file uploads to work was to actually set the "upload_tmp_dir " to an absolute path, pointing to my temp dir.

      Something like:
      Code:
      upload_tmp_dir = "C:\\temp"
      Not 100% sure about the double \'s. If that doesn't work, you could try a single \ or a single /.
      I also had to reboot the computer a couple of times before that actually started working.

      Second, you could try removing the:
      [code=html]<input type="hidden" name="MAX_FILE_ SIZE" value="300000" />[/code]
      from your form.
      I think it may be in the wrong place, and besides that, it isn't really needed.

      Comment

      • rveetil
        New Member
        • Nov 2008
        • 2

        #4
        Originally posted by Atli
        As to your question, I have two suggestions.

        First, I remember setting up a Windows server once (before I stopped trying to shoot myself in the leg and moved on to Linux).
        The only way I managed to get the file uploads to work was to actually set the "upload_tmp_dir " to an absolute path, pointing to my temp dir.

        Something like:
        Code:
        upload_tmp_dir = "C:\\temp"
        Not 100% sure about the double \'s. If that doesn't work, you could try a single \ or a single /.
        I also had to reboot the computer a couple of times before that actually started working.

        Second, you could try removing the:
        [code=html]<input type="hidden" name="MAX_FILE_ SIZE" value="300000" />[/code]
        from your form.
        I think it may be in the wrong place, and besides that, it isn't really needed.

        All the recommendations you suggested are tested with no success. Not sure what to do next. I'm not able to identify the problem is related to PHP version or Tomcat version. Unfortunately I don't have a Linux machine to test the OS related issues.

        Comment

        Working...