Copy CodeThe code is as follows:
/* Image upload class only in JPG format */
Class UploadFile
{
var $inputName; Input name
var $fileName; File naming
var $fileProperty; File properties
var $fileSize = 2097152; File size limit, 2M
var $filePath = "upload/"; File storage Path
function UploadFile ($inputName) {
$this->inputname= $inputName;
$this->getname (); Get a new name
$this->filesave ();
}
Random Name
Private Function GetName () {
$this->filename=date ("Ymdhms"). Rand (0,9). $this->getproperty ();
}
File attributes, returning the suffix name
Private Function GetProperty () {
if ($_files[$this->inputname]["type"]== "Image/pjpeg" | | $_files[$this->inputname]["type"]== "Image/jpeg") {
return ". jpg";
}else{
Exit ("file format is incorrect");
}
}
File storage
Private Function FileSave () {
if ($_files[$this->inputname]["size"]> $this->filesize) {
Exit ("File is too large, maximum limit is". $this->filesize. " Bytes ");
}
if (!file_exists ($this->filepath)) {
mkdir ($this->filepath); If the file storage directory does not exist, it is established;
}
Move_uploaded_file ($_files[$this->inputname]["Tmp_name"],
$this->filepath. $this->filename);
}
}
if ($_get[' action ']== "FileSave") {
$f =new uploadfile ("file");
Echo 'Upload success! FilePath. $f->filename. ' " > browse ';
}else{
Echo ';
}
?>
The above describes the file transfer software php file upload code limit JPG file, including the file transfer software content, I hope the PHP tutorial interested in a friend helpful.