Image upload problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Redapple
    New Member
    • Mar 2007
    • 5

    Image upload problem

    Hello everybody,

    Im a beginner in PHP and i'm thinking how i can make more things on my own made upload script:

    Sorry if this is the wrong forum or if its not allowed to ask for script help/reqeusts.

    [PHP]
    <?php
    if (isset($_POST['uploadedfile'])) {
    if($_POST['uploadedfile'] == NULL) {
    die();
    }
    $target_path = "images/profiles/";
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

    if(move_uploade d_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=profile.msn w?epuid=$regcoo kie\">";
    } else{
    echo "There was an error uploading the file, please try again!";
    }

    } else {
    echo "
    <font color=\"#064f84 \" face=\"Tahoma\" size=\"2\"><b>P rofile photo</b></font>
    <br>
    <br>
    <span class=\"style10 \">
    <font face=\"Tahoma\" size=\"2\">
    Upload your own photo to your profile, Click on browse, Select your photo and press Upload!</b>
    <br><br>
    <form enctype=\"multi part/form-data\" method=\"POST\" action=\"$PHP_S ELF?action=dpph ots\">
    <input type=\"hidden\" name=\"MAX_FILE _SIZE\" value=\"100000\ " />
    Choose a image to upload: <input name=\"uploaded file\" type=\"file\" /><br /><br />
    <input type=\"submit\" value=\"Upload File\" />
    </form></font>
    </span>
    ";
    }
    ?>
    [/PHP]

    How can i add like file types and size limits, and reondom usernames. btw, this script is not working, Im just a beginner who wants to learn and get help.

    Thanks in advance.
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    Try this script. I couldn't figure out the File size limit. try to do it later.

    [PHP]<?php
    $target_path = "1234/"; //Directory Name to Upload
    if($_POST['upload'])
    {
    $newName = md5(basename($_ FILES['upload_fle']['name']));
    $ext = strrchr(basenam e($_FILES['upload_fle']['name']), ".");
    $fullName = $newName.$ext;

    if(move_uploade d_file($_FILES['upload_fle']['tmp_name'], $target_path.$f ullName))
    {
    echo "The file ". basename( $_FILES['upload_fle']['name']).
    " has been uploaded with this name : ".$fullName ;
    } else
    {
    echo "There was an error uploading the file, please try again!";
    }

    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitl ed Document</title>
    </head>

    <body>
    <form action="<? echo $PHP_SELF; ?>" method="post" enctype="multip art/form-data" name="frmAlbum" id="frmAlbum">
    <input name="upload_fl e" type="file" id="upload_fle "/>
    <BR>
    <input name="upload" type="submit" value="Upload">
    </form>
    </body>
    </html>
    [/PHP]

    Comment

    Working...