Urgent! Picture Upload Function/Page

Posted on 2006-06-01
Last Modified: 2010-07-27
I need a function that uploads a picture onto my server, but with a few tweaks and differences when compared to your run-of-the-mill upload function. Basically, the user should be able to browse throuhg their computer and locate a picture of their choice. After having pressed the submit button, the picture should be converted to a width and height that has been preselected by myself- in other words, two constants. This new picture should be stored somewhere on the server. This should be done once more for a thumbnail in the same manner, gathering the width and height from two different constants.

Thanks very much everyone!
Question by:momonja
    LVL 10

    Accepted Solution

    LVL 4

    Assisted Solution

    for the above example u need GD liberary support on php. and the picture quatity will be not good
    it just resizes the image without changing the resolution. results bad quality.

    so to get this done u need imagemagik application which is a freeware and most of the webhosting provider gives imagigmagik service.

    u will get info regarding imagemagik here
    LVL 16

    Expert Comment

    here is a working code (jpg only)
    i tried to add as musch comments as i could to let you know what is going on
    // This is the temporary file created by PHP
    $uploadedfile = $_FILES['uploadfile']['tmp_name'];

    // copy orginal image ot images folder with a prefix of large_
    copy($_FILES['uploadfile']['tmp_name'],"images/large_". $_FILES['uploadfile']['name']);

    // Create an Image from it so we can do the resize
    $src = imagecreatefromjpeg($uploadedfile);

    // Capture the original size of the uploaded image

    // new width of 100
    $newheight=($height/$width)*100; // to maintain aspect ratio

    // this line actually does the image resizing, copying from the original
    // image into the $tmp image

    // now write the resized image to disk. I have assumed that you want the
    // resized, uploaded image file to reside in the ./images subdirectory.
    $filename = "images/". $_FILES['uploadfile']['name'];

    <!--display the thumbnail -->
    <img src="<?=$filename?>">
    LVL 11

    Expert Comment

    Try this great package:

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now