Home > Backend Development > PHP Tutorial > File transfer software php file upload code limits jpg files

File transfer software php file upload code limits jpg files

WBOY
Release: 2016-07-29 08:41:35
Original
1200 people have browsed it

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.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template