From the PHP100, the function is very powerful. Almost every detail is taken into account to share with you! ~~~
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/><?PHP/****************************************************************************** parameter Description: $max _file_size: Upload file size limit, Unit byte$destination_folder: Upload file path $watermark: Whether additional watermark (1 is watermark, the other is not watermark); instruction for use: 1. The php.ini file inside the "Extension=php_gd2.dll" line in front of the, the number is removed, because we need to use the GD library; 2. Change Extension_dir = to the directory where your Php_gd2.dll is located; *************************************************************************** ***///upload file Type list$uptypes=Array( ' Image/jpg ', ' image/jpeg ', ' image/png ', ' image/pjpeg ', ' image/gif ', ' image/bmp ', ' image/x-png ');$max _file_size= 2000000;//upload file size limit, unit byte$destination _folder= "uploadimg/";//Upload file path$watermark= 1;//whether additional watermark (1 is watermark, the other is not watermark);$watertype= 1;//Watermark Type (1 for text, 2 for picture)$waterposition= 1;//The watermark position (1 is the lower left corner, 2 is the lower right corner, 3 is the upper left corner, 4 is the upper right corner, and 5 is centered);$waterstring= "http://www.xplore.cn/";//Watermark String$waterimg= "Xplore.gif";//Watermark Picture$imgpreview= 1;//whether to generate a preview map (1 is generated, others are not generated);$imgpreviewsize=1/2;//Thumbnail scale>body{Font-size:9pt;} input{background-color:#66CCFF;border:1px inset#CCCCCC;}--></style>Uploading Files: <input name= "upfile" type= "file" > <input type= "Submit" value= "Upload" ><br>the file types allowed to upload are: <?=implode(‘, ‘,$uptypes)? ></form><?PHPif($_server[' request_method '] = = ' POST '){ if(!Is_uploaded_file($_files["Upfile"][tmp_name]))//whether the file exists { Echo"The picture doesn't exist!"; Exit; } $file=$_files["Upfile"]; if($max _file_size<$file["Size"]) //Check File size { Echo"The file is too big!"; Exit; } if(!In_array($file["Type"],$uptypes)) //Check file Types { Echo"File type does not match!".$file["Type"]; Exit; } if(!file_exists($destination _folder)) { mkdir($destination _folder); } $filename=$file["Tmp_name"]; $image _size=getimagesize($filename); $pinfo=PathInfo($file["Name"]); $ftype=$pinfo[' extension ']; $destination=$destination _folder. Time().".".$ftype; if(file_exists($destination) &&$overwrite!=true) { Echo"File with the same name already exists"; Exit; } if(!Move_uploaded_file($filename,$destination)) { Echo"Move File Error"; Exit; } $pinfo=PathInfo($destination); $fname=$pinfo[basename]; Echo"<font Color=red> has successfully uploaded </font><br> FileName: <font color=blue>".$destination _folder.$fname." </font><br> "; Echo"Width:".$image _size[0]; Echo"Length:".$image _size[1]; Echo"<br> size:".$file["Size"]. " bytes; if($watermark==1) { $iinfo=getimagesize($destination,$iinfo); $nimage=imagecreatetruecolor ($image _size[0],$image _size[1]); $white=imagecolorallocate ($nimage, 255,255,255); $black=imagecolorallocate ($nimage, 0,0,0); $red=imagecolorallocate ($nimage, 255,0,0); Imagefill ($nimage, 0, 0,$white); Switch($iinfo[2]) { Case1:$simage=imagecreatefromgif ($destination); Break; Case2:$simage=imagecreatefromjpeg ($destination); Break; Case3:$simage=imagecreatefrompng ($destination); Break; Case6:$simage=imagecreatefromwbmp ($destination); Break; default: die("Unsupported File Types"); Exit; } imagecopy ($nimage,$simage, 0,0,0,0,$image _size[0],$image _size[1]); Imagefilledrectangle ($nimage, 1,$image _size[1]-15,80,$image _size[1],$white); Switch($watertype) { Case1://Add watermark StringImagestring ($nimage, 2, 3,$image _size[1]-15,$waterstring,$black); Break; Case2://Add watermark Image $simage 1=imagecreatefromgif ("Xplore.gif"); Imagecopy ($nimage,$simage 1, 0,0,0,0,85,15); Imagedestroy ($simage 1); Break; } Switch($iinfo[2]) { Case1://imagegif ($nimage, $destination);Imagejpeg ($nimage,$destination); Break; Case2:imagejpeg ($nimage,$destination); Break; Case3:Imagepng ($nimage,$destination); Break; Case6:Imagewbmp ($nimage,$destination); //imagejpeg ($nimage, $destination); Break; } //overwrite the original upload fileImagedestroy ($nimage); Imagedestroy ($simage); } if($imgpreview==1) { Echo"<br> picture preview:<br>"; Echo"$destination." \ "Width=". ($image _size[0]*$imgpreviewsize). "Height=". ($image _size[1]*$imgpreviewsize); Echo"Alt=\" Picture preview: \ r file name: ".$destination." \ r upload time: \ ">"; }}?></body>Reprint: http://blog.csdn.net/niushuai666/article/details/6672808
PHP image upload Program (full version)