上傳檔案判斷檔案名稱是否重複

來源:互聯網
上載者:User
上傳檔案判斷檔案名稱是否重複請指教
上傳檔案時候如何判斷 檔案名稱重複?
上傳檔案我知道
$_FILES["表單名字"]
$_FILES["表單名字"]["name"]名字
如何擷取上傳路徑文檔裡面的圖片名字?


class UpFile{
private $name; //名字
private $type;//類型
private $size;//大小
private $tempDirectory;//伺服器的臨時路徑
private $directory;//的實際路徑 (臨時 移動 實際)
private $allowType;//允許的檔案類型
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(){ //是否有檔案 1或0 1代表有
return is_uploaded_file($this->tempDirectory);
}
function moveFile(){//檔案移動
move_uploaded_file($this->tempDirectory,$this->directory);
}
function iftype(){//檢查檔案類型 unlink(路徑);//檔案刪除方法
if(in_array($this->type,$this->allowType)){
return true;
}else{
return false;
}
}
function ifName(){
//如何判斷上傳的檔案名稱與已上傳的檔案名稱重複
}
}
?>


include("UpFile.php");
$upfile = new UpFile($_FILES["upfile"]);

?>




------解決方案--------------------
$file=$_FILES["表單名字"]["name"];
if(file_exists($file))
echo 'exist';
else
move_uploaded_file()........
------解決方案--------------------
if(file_exists($this->tempDirectory)) echo '檔案已存在';
------解決方案--------------------
按照規則先產生絕對路徑,然後就能知道該路徑下的檔案是否存在了唄...
不過這種做法很不安全,建議還是完全隨機的檔案名稱。
------解決方案--------------------
探討
$file=$_FILES["表單名字"]["name"];
if(file_exists($file))
echo 'exist';
else
move_uploaded_file()........
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.