亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

php 文件上傳代碼(限制jpg文件)

 更新時(shí)間:2010年01月05日 22:26:35   作者:  
php 文件上傳代碼,限制jpg文件,需要的朋友可以參考下。
復(fù)制代碼 代碼如下:

<?php
/* 圖片上傳類(lèi)  僅限JPG格式圖片 */
class uploadFile
{
var $inputName; //input名稱(chēng)
var $fileName; //文件命名
var $fileProperty; //文件屬性
var $fileSize=2097152; //文件大小限制,2M
var $filePath="upload/"; //文件存儲(chǔ)路徑
function uploadFile($inputName){
$this->inputName=$inputName;
$this->getName(); //取得新的名稱(chēng)
$this->fileSave();
}
//隨機(jī)名稱(chēng)
private function getName(){
$this->fileName=date("YmdHms").rand(0,9).$this->getProperty();
}
//文件屬性,返回后輟名
private function getProperty(){
if($_FILES[$this->inputName]["type"]=="image/pjpeg"||$_FILES[$this->inputName]["type"]=="image/jpeg"){
return ".jpg";
}else{
exit("文件格式不對(duì)");
}
}
//文件存儲(chǔ)
private function fileSave(){
if($_FILES[$this->inputName]["size"]>$this->fileSize){
exit("文件太大,最大限制為".$this->fileSize."字節(jié)");
}
if(!file_exists($this->filePath)){
mkdir($this->filePath); //如果文件存儲(chǔ)目錄不存在,則建立;
}
move_uploaded_file($_FILES[$this->inputName]["tmp_name"],
$this->filePath.$this->fileName);
}
}
if($_GET['action']=="fileSave"){
$f=new uploadFile("file");
echo '<input name="textfield" type="text" size="30" value="'.$f->filePath.$f->fileName.'" /> 上傳成功! <a href="'.$f->filePath.$f->fileName.'">瀏覽</a>';
}else{
echo '<form action="?action=fileSave" method="post" enctype="multipart/form-data" name="form1" id="form1">
<input type="file" name="file" size="30" />
<input type="submit" name="Submit" value="提交" />
</form>';
}
?>

相關(guān)文章

最新評(píng)論