Upload a file to determine whether the file name is repeated

Source: Internet
Author: User
Determine whether a file name is repeated during File upload. how can I determine whether a file name is repeated during File upload? I know $ _ FILES [& quot; form name & quot;] $ _ FILES [& quot; form name & quot;] [& quot; name & quot;] how does one obtain the image name in the upload path document? & Lt; upload a file to determine whether the file name is repeated. please advise
How can I identify duplicate file names during File upload?
Upload file I know
$ _ FILES ["form name"]
$ _ FILES ["form name"] ["name"] name
How do I obtain the image name in the upload path document?


Class UpFile {
Private $ name; // name
Private $ type; // type
Private $ size; // size
Private $ tempDirectory; // temporary path of the server
Private $ directory; // The actual path of the directory (temporarily move the actual path)
Private $ allowType; // allowed file types
Private $ error;

Function _ construct ($ FILE ){
$ This-> name = $ FILE ["name"];
$ This-> type = $ FILE ["type"];
$ This-> size = $ FILE ["size"];
$ This-> tempDirectory = $ FILE ["tmp_name"];
$ This-> directory = "../image/". $ this-> name;

$ This-> allowType = array (
'Image/jpg ',
'Image/png ',
'Image/GIF ',
'Image/pjpeg'
);
$ This-> error = $ FILE ["error"];
}
Function isUpFile () {// indicates whether a file exists. 1 or 0 1 indicates that a file exists.
Return is_uploaded_file ($ this-> tempDirectory );
}
Function moveFile () {// File Movement
Move_uploaded_file ($ this-> tempDirectory, $ this-> directory );
}
Function iftype () {// check the file type unlink (path); // delete the file
If (in_array ($ this-> type, $ this-> allowType )){
Return true;
} Else {
Return false;
}
}
Function ifName (){
// Determine whether the uploaded file name is the same as the uploaded file name
}
}
?>


Include ("UpFile. php ");
$ Upfile = new UpFile ($ _ FILES ["upfile"]);

?>




------ Solution --------------------
$ File = $ _ FILES ["form name"] ["name"];
If (file_exists ($ file ))
Echo 'exist ';
Else
Move_uploaded_file ()........
------ Solution --------------------
If (file_exists ($ this-> tempDirectory) echo 'file already exists ';
------ Solution --------------------
Follow the rules to create an absolute path, and then you can know whether the file in the path exists...
However, this method is not safe. we recommend that you use a random file name.
------ Solution --------------------
Discussion
$ File = $ _ FILES ["form name"] ["name"];
If (file_exists ($ file ))
Echo 'exist ';
Else
Move_uploaded_file ()........

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.