Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/content/86/3464586/html/rkWebsites/allfree-stuff.com/conn.php on line 11
allfree-stuff.com - Free Tutorials, Ebooks, Source Codes, Question Bank
Logo Tutorials, Ebooks, Source Codes, Question Bank
Submit your Email ID & receive intimation about New/Updated Contents :
Advertise with us             CONTACT US
 
Android MobilesHTC MobilesMicromax MobilesMobile ArticlesMobile TermsNokia MobilesSamsung MobilesSony MobilesTablets
108 Names of GodBhajans CHALISA CollectionDevi Maa Ki AartiyanGanesh Ji Ki AartiyanHanuman Ji Ki AartiyanRadha Krishan Ji Ki AartiyanRam Ji Ki AartiyanSai Baba Ji Ki AartiyanShiv Ji Ki AartiyanTemples in IndiaVishnu Ji Ki Aartiyan
Wallpapers Pack
Bollywood FlashsFestival FlashsFlash GamesFlash MessagesFunny FlashsPatriotic FlashsPolitical FlashsSpiritual Flashs
FunStuffJokesRajnikanth JokesWhats App JokesWhats App Messages
About IndiaGeneral Knowledge Hindi RhymesMythological StoriesNursery RhymesPatriotic SongsRiddlesShort StoriesTongue Twisters
Funny SlideshowsInteresting SlideshowsMessage SlideshowsNice SlideshowsPatriotic SlideshowsSpiritual Slideshows
BirthDay SMSChristmas SMSClassic SMSFathers Day SMSFestivals SMSFriendship SMSFunny SMSHoli SMSHusbandWife SMSIndependenceDay SMSLohri SMSLove SMSMorning SMSMothers Day SMSNew Year SMSNight SMSPoetry SMSPunjabi SMSRakhi SMSSanta Banta SmSTeachers Day SMSTimePass SMSValentine Day SMS
3D WallpapersAbstract_WallpapersAnimated_WallpapersApple_Mac_WallpapersBaby_WallpapersBackGroundsBeach WallpapersBirds WallpapersCars WallpapersCartoon_WallpapersChristmas WallpapersColorFul_WallpapersColoringSheetsCool_WallpapersFish_WallpapersFlagsFlash TattoosFlowersFunny WallpapersGalleryGodsGreen_ScenesHD_High_ResolutioniPhone WallPapersLinux_WallpapersMobile_WallpapersMortality WallpapersMountain_WallpapersNatureOptical_IllusionsRosesSea_WallpapersShips WallpapersSports_GamesUltraBeautiful WallpaperValentine WallpapersVehiclesWideScreen WallpapersWildLife WallpapersWindows VistaWindowsXPWindows_7_Wallpapers
AJAX ASP.Net 2.0/3.5 C# / C-Sharp C/C++ Cryptography Data Compression Data Structures FLASH Foxpro/VFP HTML JAVA Java Scripts JSP LINUX Microsoft Office Microsoft Windows MS XNA PHP/MySQL Silverlight Software Engineering SQL SQL Server 2005 UNIX VB.Net 2005 VBScript XML

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/content/86/3464586/html/rkWebsites/allfree-stuff.com/conn.php on line 11
Home Search

?>
       
  
PHP/MySQL
Articles
PHP File Uploading with Example

 

PHP File Uploading with Example

A very useful aspect of PHP is its ability to manage file uploads to your server. Allowing users to upload a file to your server opens a whole can of worms, so please be careful when enabling file uploads.

PHP - File Upload: HTML Form

Before you can use PHP to manage your uploads, you must first build an HTML form that lets users select a file to upload. See our HTML Form lesson for a more in-depth look at forms.

<form enctype="multipart/form-data" action="uploader.php" method="POST"
>
<input type=
"hidden" name="MAX_FILE_SIZE" value="100000"
/>
Choose a file to upload: <input name="uploadedfile" type="file" />
<br />
<input type="submit" value="Upload File"
/>
</form>
keep this code within body tag.

enctype="multipart/form-data" - Necessary for our to-be-created PHP file to function properly.


PHP - File Upload: move_uploaded_file Function

Now all we have to do is call the move_uploaded_file function and let PHP do its magic.
The move_uploaded_file function needs to know two variables -
1) The path of the temporary file (check!)
2) The path where it is to be moved to (check!).

PHP Code:
<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else
{
echo "There was an error uploading the file, please try again!";
}
?>

You will need to create a new directory in the directory where uploader.php resides, called "uploads", as we are going to be saving files their and don't forget to make the folder write mode then only the file will be upload .

 








allfree-stuff.com - Free Education for ALL - for any queries contact @ webmaster@allfree-stuff.com