<!doctype HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/ Xhtml1-transitional.dtd "> <meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/> <title> Upload File Program </title> <style type= "Text/css Tutorial" > *{ font-size:12px; margin:0; padding:0; } a:link,a:visited{ Text-decoration:none; Color: #393 } a:hover{ Text-decoration:underline; Color: #0033cc } input.text{ border:1px solid #ccc; Height:22px;line-height:22px;padding-left:5px;background: #fff; width:274px; } input.button{ Background: #fff URL (images/button.png), border:1px solid #9ea9c5;p adding:2px 2px 0px 2px;margin-left:4px; margin-right:4px; } </style> <script language= Web page Special effects > function Check () { var Strfilename=document.myform.upfile.value; if (strfilename== "") { Alert ("Please select the file to upload"); Document.myform.upfile.focus (); return false; } } </script> <body> <?php /*********************** Programs: Uploading Files Function: Upload files, thumbnails, watermark ****************************/ Include ("common/upfiles.class.php"); $path = ". /upload/coolsite "; File Upload Path $mix = "Smallimg"; Thumbnail path (established under upload) $mark = "Markimg"; Add water to the picture store path (established under upload) $text = Array ("Www.111cn.net"); Watermark Content $oupload = new Upfiles ($path, $mix, $mark); Instantiating class files if (Isset ($_post[' up ')) {
if ($_post[' Urlid ']== ' 1 ') {//Upload picture parameters Urlid 1: Upload image 2: Upload other files.
$oupload->tofile = true; Open to save only thumbnails or watermarks, delete the original image $photo = $oupload->upload ("Upfile"); Uploaded file fields $photourl = $oupload->fileurl. " /". $photo; $newsmallimg = $oupload->smallimg ($photo); Thumbnail function $newmarkimg = $oupload->watermark ($photo, $text); Watermark function Echo $newsmallimg; Output thumbnail path Echo $newmark; Output Watermark Map Path echo " '; Output thumbnails echo " '; Output Watermark Map }else{ $upfilename = $oupload->upload ("Upfile"); Uploaded file fields } $strjs = "<script language=javascript>"; $strjs. = "Parent.document.myform.upfile1.value= '". $newsmallimg. "' "; $strjs. = "Parent.document.myform.upfile2.value= '". $photourl. "' "; $strjs. = "</script>"; Echo $strjs; Attach the last file path to Upfile1, Upfile2 }else{ ?> <form action= "upfile.php" method= "post" enctype= "Multipart/form-data" name= "MyForm" onsubmit= "return Check ()" > <input type= "File" Name= "Upfile" value= "class=" text "><input type=" Submit "name=" Up "value=" Upload "class=" Button "> <input type= "hidden" name= "Urlid" value= "<?php echo $_get[' urlid '"]?> "> </form> <?php}?> </body> ? upfiles.class.php /*========================= Upload class upfiles.class.php ===========================*/ Class Upfiles { /*========================= Basic parameter Settings ===========================*/ protected $annexfolder = "Upload"; Attachment storage point, defaults to: Upload protected $dirtype = 2; 1: By day in the Directory 2: Monthly directory protected $smallfolder = "smallimg"; Thumbnail store path, note: Must be placed under the $upload subdirectory, the default is: smallimg protected $markfolder = "markimg"; Watermark Picture Store Path, note: Must be placed under the $upload subdirectory, the default is: markimg protected $upfiletype = "jpg gif png rar zip"; Type of upload, default: JPG gif png rar zip protected $upfilemax = 102400; Upload size limit, the unit is "KB", the default is: 1024KB protected $fonttype = "COMMON/EQUINOXSTD.OTF"; Watermark Font Library protected $maxwidth = 800; Picture Maximum width protected $maxheight = 600; Picture Max height
/*========================= Initialize Upload class ===========================*/ Public function __construct ($annexfolder, $smallfolder, $includefolder) {
Switch ($this->dirtype) { Case 1: $attach _subdir = ' Day_ '. Date (' Ymd '); Break Case 2: $attach _subdir = ' month_ '. Date (' ym '); Break } $attach _dir = $annexfolder. ' /'. $attach _subdir; $attach _dir_small = $attach _dir. $smallfolder; $attach _dir_mark = $attach _dir. $includefolder;
$this->rootfolder = $annexfolder; $this->annexfolder = $attach _dir; $this->smallfolder = $attach _dir_small; $this->markfolder = $attach _dir_mark; $this->fonttype = $includefolder. " /nasaliza.ttf "; } Public Function __get ($fileurl) { $fileurl = $this->annexfolder; return $fileurl; } /*========================= Uploading files ===========================*/ Public function upload ($inputname) { Check if a folder exists if (!file_exists ($this->annexfolder)) { if (!file_exists ($this->rootfolder)) @mkdir ($this->rootfolder); if (!file_exists ($this->annexfolder)) @mkdir ($this->annexfolder); if (!file_exists ($this->smallfolder)) @mkdir ($this->smallfolder); if (!file_exists ($this->markfolder)) @mkdir ($this->markfolder); } if (!file_exists ($this->smallfolder)) { @mkdir ($this->smallfolder); } if (!file_exists ($this->markfolder)) { @mkdir ($this->markfolder); }
$this->uptype = $_files[$inputname] ["type"]; $this->upname = $_files[$inputname] ["name"]; $this->uptmp_name = $_files[$inputname] ["Tmp_name"]; $this->ups Tutorial ize = $_files[$inputname] ["size"]; $this->uperror = $_files[$inputname] ["Error"]; if ($this->uptype) { Switch ($this->uptype)///Check the type of upload { Case "Image/pjpeg": $fileextname = "JPG"; Break Case "Image/jpeg": $fileextname = "JPG"; Break Case "Image/gif": $fileextname = "gif"; Break Case "Image/x-png": $fileextname = "png"; Break Case "Application/x-shockwave-flash": $fileextname = "SWF"; Break Case "Text/plain": $fileextname = "txt"; Break Case "Application/msword": $fileextname = "Doc"; Break Case "application/vnd.ms-excel": $fileextname = "xls"; Break Case "application/x-zip-compressed": $fileextname = "zip"; Break Case "Audio/mpeg": $fileextname = "MP3"; Break Case "AUDIO/X-MS-WMA": $fileextname = "WMA"; Break Case "Application/pdf": $fileextname = "PDF"; Break Default://If the above type is not met, the upload file is judged to be malformed!! $fileextname =strtolower (substr (STRRCHR) (Trim ($this->upname), "."), 1,4)); $fileinfo =pathinfo ($this->upname); $fileextname = $fileinfo [' extension ']; $fileextname = "Err"; } }
|