File transfer software php file upload code limit JPG file

Source: Internet
Author: User
Tags php file upload
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.