Website Babble Webmaster Forums  


Go Back   Website Babble Webmaster Forums > Creating a Website > HTML, PHP, CSS, Javascript & Coding/Programming Topics

Your WB Notifications

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-07-2009, 06:07 AM
Junior Babbler
 
Join Date: Jul 2009
Posts: 13
johnfrey has no reputation at Website Babble yet.
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
  #2 (permalink)  
Old 08-07-2009, 01:25 PM
Johnny's Avatar
Master Babbler
 
Join Date: Apr 2008
Location: Cleveland/ Columbus, Ohio
Posts: 146
Johnny has a rock solid WB reputation (over 200 points)Johnny has a rock solid WB reputation (over 200 points)Johnny has a rock solid WB reputation (over 200 points)
Send a message via AIM to Johnny
Default

...You haven't actually tried this yourself, have you?

__________________
Yellow Aeroplane Web Solutions
Reply With Quote
  #3 (permalink)  
Old 09-17-2009, 05:17 AM
Regular Babbler
 
Join Date: Sep 2009
Posts: 34
uptown47 has no reputation at Website Babble yet.
Default

Your example will not work, I'm not sure where you got it from but as Johnny says, you mustn't have tried it out.

For starters, where does $userfile_size come from?

You maybe want to compare:
$_FILES["userfile"]["size"] > 250000

If someone is reading this thread please do not panic when the above example doesn't work for you. It is not complete.

Reply With Quote
  #4 (permalink)  
Old 09-19-2009, 04:12 PM
Junior Babbler
 
Join Date: Aug 2009
Location: I am currently in Chandler Arizona.
Posts: 29
mbalrog6 has more than the average amount of reputation points
Default File upload assistance

Here is a link to a site that will illustrate exactly how to properly do a file upload.
http://tuxradar.com/practicalphp/8/10/0

You need to use the super array $_FILES to access uploads.

the path that actually contains the file is $_FILES['form-element-name']['tmp_name']
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -6. The time now is 10:44 PM.


 Subscribe to RSS

WB Sponsors

flash chat

Home Jobs Online

Search Engine Marketing

Paid Surveys

Web Design Newcastle

Bookmarking Demon 5



 Subscribe to the Website Babble Feeds

2 Create a Website Homepage | 2 Create a Website Blog


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0