PHP Tutorial File Upload Program
The article provides a complete set of PHP file upload program instance code, he can upload pictures and save the picture to 1: by the day into the Directory 2: Monthly deposit directory, you can also set the upload image to create a watermark,
*/
?>
Upload File Program
/***********************
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"; Picture storage path for water citation (established under upload)
$text = Array ("www.bKjia.c0m"); Watermark Content
$oupload = new Upfiles ($path, $mix, $mark); Instantiating a class file
if (Isset ($_post[' up ')) {
if ($_post[' Urlid ']== ' 1 ') {//upload picture parameter 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 thumbnail image
echo ""; Output Watermark Map
}else{
$upfilename = $oupload->upload ("Upfile"); Uploaded file fields
}
$strjs = "n";
Echo $strjs; Attach the last file path to Upfile1, Upfile2
}else{
?>
upfiles.class.php
/*=========================
Upload class upfiles.class.php
===========================*/
Class Upfiles {
/*=========================
Basic parameter Settings
===========================*/
protected $annexfolder = "Upload"; Attachment storage point, default: Upload
protected $dirtype = 2; 1: Deposit by day Directory 2: Monthly deposit Directory
protected $smallfolder = "smallimg"; Thumbnail storage path, note: Must be placed under the $upload subdirectory, the default is: smallimg
protected $markfolder = "markimg"; Watermark Image Storage Path, note: Must be placed under the $upload subdirectory, the default is: markimg
protected $upfiletype = "jpg gif png rar zip"; Upload type, default: JPG gif png rar zip
protected $upfilemax = 102400; Upload size limit, in kilobytes, default: 1024KB
protected $fonttype = "COMMON/EQUINOXSTD.OTF"; Watermark Font Library
protected $maxwidth = 800; Max width of picture
protected $maxheight = 600; Maximum height of picture
/*=========================
Initialize the 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, then the upload file is judged to be in an incorrect format!!
$fileextname =strtolower (substr (STRRCHR (Trim ($this->upname), "."), 1,4);
$fileinfo =pathinfo ($this->upname);
$fileextname = $fileinfo [' extension '];
$fileextname = "Err";
}
}
1 2
http://www.bkjia.com/PHPjc/631742.html www.bkjia.com true http://www.bkjia.com/PHPjc/631742.html techarticle PHP Tutorial File Upload Program article provides a complete set of PHP file upload program instance code, he can upload pictures and save the picture to 1: By day Deposit Directory 2: Monthly deposit directory ...