PHP upload a picture


Back to programming.


moderator    (2009-03-31)

moderator

PHP upload a picture

How to upload a picture on a server ?

Here are pieces of script I use to upload a picture on the FICGS server in PHP, of course it is possible to resize, crop the picture & so on (see PHP functions). Feel free to use or change it

First you have to make the form :

<form enctype="multipart/form-data" action="process.php" method="post">
<input type="hidden" name="photo" value="photo" />
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
 
<table border="0" width="500" align="center">
  <tr>
    <td width="75">&nbsp;</td>
    <td>upload a photo, JPG format, max. size : 10 Mb<font size="1"><br><br></font>
      <input type="file" size="22" name="photo"> &nbsp; &nbsp; <input type="submit" name="send" value="Send" /></td>
  </tr>
</table>
</form>


Then in process.php you have to check the picture & save it, here I only verify if the picture is square enough then I resize it, copy it & change rights :

if (!empty($_POST['photo']))
{
@unlink($photo_directory.$photo_file);

if (is_uploaded_file($_FILES['photo']['tmp_name']))
{
    $img_size = GetImageSize($_FILES['photo']['tmp_name']);

    if ($img_size[0] / $img_size[1] <= 1.5 AND $img_size[0] / $img_size[1] >= 0.666)
{
    rename($_FILES['photo']['tmp_name'], $photo_directory.$photo_file);

    chmod($photo_directory.$photo_file,0755);

    list($photo_width,$photo_height) = getimagesize($photo_directory.$photo_file);
 
    $photo_resource = imagecreatefromjpeg($photo_directory.$photo_file);

    if ($photo_width > 220) {  $new_height = $photo_height * 220 / $photo_width;  $new_width = 220; }
else  {  $new_height = $photo_height;  $new_width = $photo_width;  }

    $photo_resource_resampled = imagecreatetruecolor($new_width, $new_height);

    imagecopyresampled($photo_resource_resampled, $photo_resource, 0, 0, 0, 0, $new_width, $new_height, $photo_width, $photo_height);
    imagejpeg($photo_resource_resampled,$photo_directory.$photo_file);
}
}
}




(more options below)

*e93789    (2009-12-21 22:53:34)
PHP upload a picture




*curava    (2010-10-22 11:49:26)
13 years ago

i want the uploaded picture display on the form.
                                RAYMOND


See also


ficgs
More websites

You must register to see these links, as this is a collaborative page, then you may change the order of the links by clicking the icons before the titles.



admin
Other websites

The following links might be less relevant, please change their ranks if you find them useful.


 PHP Tutorial - File Upload
tizag
  1. ! To save our precious file we are going to need to make use of the
  2. function needs to know 1) The path of the temporary file (check!) 2)
 Example - PHP form, Image upload. Store in MySQL database. Retrieve.
wellho > solutions

Please note that articles in this section of our web site were...
Suggesting alternative search terms to web site...

 PHP file or picture upload script tutorial and code
plus2net

We will limit ourselves to these two type checks and if we find...
if(move_uploaded_file ($userfile, $add)){ // do your coding here to...

 Tips & Tricks - A Picture Upload in PHP
htmlgoodies > beyond/webmaster/article.

 Download Free Source Php Upload Picture Source Codes, Free Source Php Upload Picture Scripts - Pigalle - a picture gallery by phpee.com, Classified Ad...
sourcecodeonline > list?q=free source

The Fantastic Picture of the Day is a PHP based image gallery script...
Pigalle - a picture gallery has a collection of PHP coded modules...

 Re: [PHP] upload picture - Usenet Forums
usenet forums

-- +-----------------+-----------------+----------------+ |...

 php upload/resize picture - ProgrammingTalk
programmingtalk > showthread.

 GetAFreelancer.com - php upload photo display projects
getafreelancer > projects/by tag

 TinyPic - Free Image Hosting, Photo Sharing & Video Hosting
tinypic

that lets you easily upload, link, and share your images and videos...

 phpAlbum | PHP Photo Album - Gallery
phpalbum

is an Open Source PHP script which allows you to create your...
I thing this is very cool feature and you will definitely like...

 » Free Upload multiple picture php script
findmysoft > scripts/upload multiple picture

Dating Agent III - Dating Script with Source Code...

 Tokyoahead - PHP: Upload pictures for webpages easily
tokyoahead > main/article.

 PHP Image Galleries | Scripts & Programs | Hot Scripts
hotscripts > category

calculations, instant downloads, PayPal and 2Checkout integration,...
networking functions, drag and drop slideshow creation system, multi...

 Can only upload one picture at a time
forum.coppermine gallery > index.

It is with great pride that the Coppermine community announces to...
Iran, Islamic Republic of Posts: 3689...

 PHP Upload image : php, upload, image
experts exchange > Web/Web Languages

 ERROR: The requested URL could not be retrieved
shareapic > ref.

 Glitterfy.com - MySpace Glitter Graphics
glitterfy > upload.

 Php upload photos script - PHP
daniweb > forums/thread182686

/************************************Resizing the image...
Anyways this code is fine, although because i have several...

 upload picture - debug [Archive] - CodingForums.com
codingforums > archive/index.

I think you are missing an end } before the last closing...

 WordPress MU › How to use image upload? Inline-uploading.php « WordPress MU Forums
mu.wordpress > forums/topic.

 Uploading Image File Through JSP Code To Server
astahost > info.

cm hago por favor a tener mi prpoa bae de datos en esta web, con...
Searching Video's for uploading, image, file, jsp, code,...
This textarea will convert to Rich-Text automatically (IE, Firefox,...

 A code that will browse and * on my php page
ozzu > programming forum/code that will browse and upload picture

  * using php [Archive] - kirupaForum
kirupa > forum/archive/index.

 In-a-Flash Flash Upload Utility - Flash/PHP Upload Progress Bar
inaflashuploader

* In-a-Flash Flash Upload Utility should also be able to work with...
In-a-Flash is setup by default to upload the files into a folder...
Legal: The In-a-Flash Uploader can be downloaded and distributed...

 PHP & jQuery image upload and crop | WebMotionUK
webmotionuk

wpml_getlistfields('1','452368911','listfieldsdiv452368911','',...
I guess the error devil was walking by: the AND operator...
function preview(img, selection) { var scaleX = 100 /...

 PHP :: Upload Photo With Other Info
bigresource

 PEAK XOOPS - v2.50beta01 uploading picture problem ...
xoops.peak.ne > md/d3forum/index.

I think there is a core bug and now being reported by...

 Fix server php settings for picture upload (getafreelancer) - MisterSoft FreeLance Projects
mistersoft > freelancing/getafreelancer/2008/10/Javascript Linux

 Uploading Pictures
trap17 > index.

 Upload Image Php Mysql : php Image Gallery script, share images / photos online, How to Store Image in MySQL, SimPHP Gallery, Pay Pal Storefront Php ...
vclcomponents > s/0 /upload image

Uploading, Saving and Downloading Binary Data in MySQL...
All trademarks are the sole property of their respective...

 Can't upload picture/avatar without PHP GD extension enabled | drupal.org
drupal > node/17477

 Photo Editing Tool in PHP |
sajithmr > online photoshop in

 Upload picture from winmobile (C#) using php - bytes
bytes > topic/mobile development/answers/853450 upload picture winmobile c using

Remote DB connecting and simple newb walkthroughs in WinMobile 6...
SA Upload SQL Database variable types (image upload and...
Cyprus, The easiest way to add a web service...

 [TKL] upload_handler.php
lists.indexdata > pipermail/tkl/2004 May/000502

 Upload by MMS | PHP Photo Validation
merenkov > attach

 Download Php Upload Script Software: ClipShare PRO - Video Sharing Script - Youtube Clone, MultiPowUpload, ASP Pure File Upload With Progress, ...
filebuzz > findsoftware

 Need A Php Upload Page For My website? - Yahoo! Answers
answers.yahoo > question/index?qid=20081025191128AAFwMIl

I am really intrested in game design and i need a good book or video...
Yahoo! does not evaluate or guarantee the accuracy of any Yahoo!...

 The PHP Resource Index: Complete Scripts: Images and Graphs: Image Indexing
php.resourceindex > Complete Scripts/Images and Graphs/Image Indexing



Response  
 

Guest name   (option)     Register
Please sum : 884 + six  




Trackbacks : If you talked about this article in your blog or website, you may instantly get a backlink 
There's no trackback at the moment.