Copy the code The code is as follows:
/* Image upload class Only JPG format images*/
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 properties, return the suffix name
private function getProperty(){
if($_FILES[$this->inputName]["type"]=="image/pjpeg"||$_FILES[$this->inputName]["type"]=="image/jpeg") {
return ".jpg";
}else{
exit("Incorrect file format");
}
}
//File storage
private function fileSave(){
if($_FILES[$this->inputName ]["size"]>$this->fileSize){
exit("The file is too large, the maximum limit is ".$this->fileSize."bytes");
}
if(!file_exists( $this->filePath)){
mkdir($this->filePath); //If the file storage directory does not exist, create it;
}
move_uploaded_file($_FILES[$this->inputName]["tmp_name "],
$this->filePath.$this->fileName);
}
}
if($_GET['action']=="fileSave"){
$f=new uploadFile("file" );
echo ' Upload successful! Browse';
}else{
echo '
The above has introduced the file transfer software PHP file upload code to limit jpg files, including the content of the file transfer software. I hope it will be helpful to friends who are interested in PHP tutorials.