Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Urgent! Picture Upload Function/Page

Posted on 2006-06-01
6
Medium Priority
?
215 Views
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!
0
Comment
Question by:momonja
4 Comments
 
LVL 10

Accepted Solution

by:
ClickCentric earned 1000 total points
ID: 16813307
0
 
LVL 4

Assisted Solution

by:anilande
anilande earned 1000 total points
ID: 16813580
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 http://www.imagemagick.org/script/index.php
0
 
LVL 16

Expert Comment

by:dr_dedo
ID: 16816258
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
enjoy
-----------------------------------
<?php
// 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
list($width,$height)=getimagesize($uploadedfile);

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

// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

// 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'];
imagejpeg($tmp,$filename,100);

imagedestroy($src);
imagedestroy($tmp);
?>
<!--display the thumbnail -->
<img src="<?=$filename?>">
0
 
LVL 11

Expert Comment

by:neester
ID: 16823815
Try this great package:

http://phpthumb.sourceforge.net/ 
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month21 days, 5 hours left to enroll

810 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