Upload file to determine if file name is duplicated

Source: Internet
Author: User
Upload file to determine if file name is repeated please advise
How do I tell the file name to repeat when uploading files?
Uploading Files I know
$_files["Form name"]
$_files["Form name" ["Name"] Name
How do I get 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;//actual path (temporary move actual)
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 () {//Is there a file 1 or 0 1 representing a
Return Is_uploaded_file ($this->tempdirectory);
}
function MoveFile () {//File move
Move_uploaded_file ($this->tempdirectory, $this->directory);
}
function Iftype () {//Check file type unlink (path);//File Delete method
if (In_array ($this->type, $this->allowtype)) {
return true;
}else{
return false;
}
}
function IfName () {
How to tell if the uploaded file name is duplicated with 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--------------------
According to the rules of the absolute path, and then you can know that the path of the file is the existence of Bai ...
This is not safe, however, and it is recommended to have a completely random file name.
------Solution--------------------
discuss
$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.