Go Back   Web Design & SEO Company > Free Scripts

Free Scripts Free Scripts to add to your website, includes Ajax, Javascript, php, Flash, CSS, HTML and more. No registration is required to download, these scripts are provided free to help you make the most of your website.

Reply
 
  #1  
Old 08-07-2009, 11:53 AM
Junior Member
 
Join Date: Jul 2009
Posts: 2
Default How to upload images using PHP

Uploading a file is a basic requirement of most of the websites. In this post, I will explain in detail about how to upload an image using PHP.

First of all, we will add HTML code to display the browse button to upload an image:

PHP Code:
<FORM ENCTYPE="multipart/form-data"  ACTION="_URL_" METHOD=POST>
Upload this file: <INPUT NAME="userfile" TYPE="file">
<
INPUT TYPE="submit" VALUE="Send File"></FORM
This code will display a text area with a browse button to upload an image. Then I'll add PHP code for processing of file upload:
PHP Code:
if ($userfile_size >250000){$msg=$msg."Your  uploaded file size is more than 250KB so please reduce the file size and then  upload. Visit the help page to know how to reduce the file size.<BR>";$file_upload="false";} 
Now, we will check that only jpeg or gif files can be uploaded into our server:
PHP Code:
if (!($userfile_type =="image/pjpeg"  OR $userfile_type=="image/gif")){$msg=$msg."Your uploaded file must be of JPG or  GIF. Other file types are not allowed<BR>";$file_upload="false";} 
Finally, running this script will add the file to the mentioned directory:

PHP Code:
if(move_uploaded_file ($userfile,  $add)){
// do your coding here to give a thanks message or any other thing.}else{echo "Failed to upload file Contact Site admin to fix the problem";} 
Reply With Quote
Top SEO Tool
Harvester and Mass Blog Commenter
Blog Comment Software

Reply

Tools
Display Modes

Similar Threads
Thread Thread Starter Forum Replies Last Post
Retro images manson4ik Free Graphics 0 11-22-2011 12:41 PM
3D Animated GIF Images manson4ik Free Graphics 1 08-12-2011 12:58 PM
Fiole upload in c# Benivolent Knowledgebase 0 04-20-2011 05:46 AM
Favicon - Yes those little bookmark images Admin Knowledgebase 0 04-05-2007 07:25 AM
CSS- Controlling background images & colors Admin Knowledgebase 0 04-04-2007 11:25 AM



Knowledgebase | SEO | Free Scripts | Free Wordpress Themes | Free Graphics

eval gzinflate base64 decode | SEO Addons


Forum time zone is GMT. Currently it's 06:05 AM.

SEO - Top



Web Design & SEO Forums