How to make a PHP uploader script?

Ive tried so many times to make them but they never work.
I want one that can allow people to upload there pictures to my site and the name of the file changes to whatever their username is. Also so the file gets sent to the file on my host called "pictures". I nearly cracked it then got stuck again lol.
Anyone know how?
(ive check and my host does allow this so thts good)


Comments

2 Responses to “How to make a PHP uploader script?”

  1. Mark M on September 6th, 2010 3:47 am

    Drop this code into a php web page:

    <?php
    if (isset($_POST['submit'])){
    //you will need to change the path to where you want to upload to. Below
    //will place the uploaded file into the same dir as this php file.
    $uploadDirFile = realpath("./") . "\\" . basename( $_FILES['uploadedfile']['name']);
    $_FILES['uploadedfile']['name'];
    $uploadMsg = "";
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uploadDirFile)) {
    $uploadMsg .= "The file ". basename( $_FILES['uploadedfile']['name']).
    " has been uploaded";
    } else{
    $uploadMsg .= "There was an error: " . error_reporting(2039) . " uploading the file, please try again!";
    }
    }
    ?>
    <html>
    <head><title>Upload File</title></head>
    </head>
    <body>
    <div align="center">
    <table width="550" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td colspan="2" class="PageText">
    <table width="100%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td>
    <?php echo $uploadMsg; ?>
    </td>
    </tr>
    <tr>
    <td>
    <div> </div>
    <FORM ENCTYPE="multipart/form-data" ACTION="<?=$_SERVER['PHP_SELF']?>" METHOD="POST">
    <INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="30000">
    Upload File: <INPUT NAME="uploadedfile" TYPE="FILE"><br />
    <INPUT TYPE="SUBMIT" NAME="submit" VALUE="Upload">
    </FORM>
    <div> </div>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </body>
    </html>

  2. dwightl.geo on September 6th, 2010 3:47 am
Powered by Yahoo! Answers