SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist spoondevil's Avatar
    Join Date
    Jun 2001
    Location
    Harlow, Essex, UK
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Uploading Image & Information

    I'm creating a site for myself and have always encountered problems when trying to get images to upload successfully. I want to do the following:

    • I fill in form with location of file on my hard drive, and a title for the image.
    • Image is uploaded and resized to fit in a 600x600px frame whilst maintaining the aspect ratio.
    • Rename the image to "$TIMESTAMP_$USERNAME" The username will be stored in the session.
    • Create a thumbnail that can fit in a 100x100px frame whilst maintaining the aspect ratio.
    • Move the 2 images to "/images/gallery/"
    • Add the new filename and the title to a table on a database.

    I know this is possible with PHP & MySQL, but how to do it is still a mystery to me. I feel loathed to pay out loads of money for a Dreamweaver Extension when I know I can do it, but I need a tutorial that can explain how to.

    Does anyone know of a tutorial for this?


    Many Thanks
    Ian Gunter

  2. #2
    SitePoint Zealot
    Join Date
    May 2004
    Location
    Planet Earth
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    you can do this

    First make a multipart/form


    <form enctype="multipart/form-data" onSubmit="submitonce(this)" action="pictureok.php" method="post">

    <input name="userfile" type="file" id="userfile" /></td>
    <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
    <input name="submit" type="submit" value="Submit" />
    </form>




    Then...

    pictureok.php_____________________________

    <?php
    $uploaddir = 'c:\apache\htdocs\yoursite\images\gallery\\';
    $uploadfile = $_FILES['userfile']['name'];
    $uploading = $uploaddir . $uploadfile;

    print "<pre>";
    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploading)) {
    print "Valid Picture. ";

    } else {
    print "File Not Valid";
    print_r($_FILES);
    }
    print "</pre>";

    ?>

    //You can create a hidden field to insert the value of the image in your databse like this
    <input name="myimage" type="hidden" value="http://localhost/yoursite/images/gallery/<? echo "$uploadfile"; ?>">

    ___________________________________________>
    In your display page you just set the img src to 100px

    <img src = "<? echo $mypicture; ?>" width="100" height="100" border="0">



    I`m not sure right now how to change tha name of the image right now but hope the example above may help you out

    Good luck
    "The Internet ? Is that thing still around ?"

  3. #3
    SitePoint Evangelist spoondevil's Avatar
    Join Date
    Jun 2001
    Location
    Harlow, Essex, UK
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers for that. It worked atraight away!!!

    I need to now get it to rename the images to "TIMESTAMP_USERNAME" and am going to have a play about with that before I bother about copying and resizing for a thumbnail.

    Ta


Bookmarks

Posting Permissions

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