Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Form will not work

Options
  • 27-01-2009 4:23pm
    #1
    Closed Accounts Posts: 73 ✭✭


    I am using this code as a learning tool, but i can not get it to input the file.

    Can any one tell me why?

    //First page is

    <title>File Upload Form</title>
    </head>
    <body>
    This form allows you to upload a file to the server.<br>

    <form action="phpScripts/getfile.php" method="post"><br>
    Type (or select) Filename: <input type="file" name="uploadFile">
    <input type="hidden" name="MAX_FILE_SIZE" value="25000" />
    <input type="submit" value="Upload File">
    </form>

    </body>
    </html>

    // This is where the info is sent

    <head>
    <title>Process Uploaded File</title>
    </head>
    <body>

    <?php

    if ( move_uploaded_file ($_FILES ,
    "../uploads/{$_FILES }") )
    { print '<p> The file has been successfully uploaded </p>';
    }
    else
    {
    switch ($_FILES )
    { case 1:
    print '<p> The file is bigger than this PHP installation allows</p>';
    break;
    case 2:
    print '<p> The file is bigger than this form allows</p>';
    break;
    case 3:
    print '<p> Only part of the file was uploaded</p>';
    break;
    case 4:
    print '<p> No file was uploaded</p>';
    break;
    }
    }


    ?>
    </body>
    </html>


    NOW: what i am getting is a blank page and image is not sent to file
    :confused::confused::confused::confused::confused::confused::confused::confused::confused::confused::confused::confused::confused::confused:


Comments

  • Registered Users Posts: 6,509 ✭✭✭daymobrew


    Add some debug code e.g.
    [PHP]<pre>
    <?php
    print_r($_FILES);
    ?>
    </pre>[/PHP]


  • Closed Accounts Posts: 30 codecrunchers


    you need to have "ENCTYPE=multipart/form-data" in your form tag. Also, is safe mode turned on etc... there could be a lot of reasons. Have you acess to the log files ? Try turning on error handling

    ini_set('display_errors', E_ALL);


  • Closed Accounts Posts: 73 ✭✭Protype


    All the settings look fine

    I have this problem with all search box which are passed to handler php

    it must be something small ??????????????


  • Registered Users Posts: 6,509 ✭✭✭daymobrew


    Check the PHP docs on file uploads.

    I suggest starting from scratch, using the docs, and add on bits as you get it working.

    Did you add the enctype="multipart/form-data" attribute to the form that, as codecrunchers suggested.


  • Closed Accounts Posts: 30 codecrunchers


    this works, and all I changed was the ENCTYPE!


    <?php



    if (!isset($_POST)) {
    echo '

    <html>
    <head>
    <title>File Upload Form</title>
    </head>
    <body>
    This form allows you to upload a file to the server.<br>
    <form ENCTYPE="multipart/form-data" action="bb.php" method="post"><br>
    Type (or select) Filename: <input type="file" name="uploadFile">
    <input type="hidden" name="MAX_FILE_SIZE" value="25000" />
    <input type="submit" value="Upload File">
    </form>
    </body>
    </html>';
    }

    else {




    if ( move_uploaded_file ($_FILES ,
    "/var/www/testing/upload/{$_FILES }") )
    { print '<p> The file has been successfully uploaded </p>';
    }
    else
    {
    switch ($_FILES )
    { case 1:
    print '<p> The file is bigger than this PHP installation allows</p>';
    break;
    case 2:
    print '<p> The file is bigger than this form allows</p>';
    break;
    case 3:
    print '<p> Only part of the file was uploaded</p>';
    break;
    case 4:
    print '<p> No file was uploaded</p>';
    break;
    }
    }

    }

    ?>


  • Advertisement
Advertisement