php實現檔案下傳的例子(附詳細源碼)

來源:互聯網
上載者:User
php實現檔案上傳的例子(附詳細源碼)

今天用PHP做了個檔案上傳工具,功能還是很完善滴,如下:

每個圖片上傳之後,都有自己的地址,改變原圖位置或重新命名時,將不會重複上傳。

一、功能:

A:檔案分類上傳

B:產生相應的檔案夾,如本例,選擇團,組建檔案夾tuan

C:點擊圖片,查看詳細

二、HTML代碼:

buding

三、Javascript代碼:


四、PHP代碼

";exit;}}$type = pathinfo($files['name']);    $type = strtolower($type["extension"]);$type =".".$type;$tmp_name = $files['tmp_name'];$md5file = md5_file($tmp_name);//產生md5檔案$new_name =$md5file.$type;    $img_relat_path = $img_path.$new_name;$img_abs_path =$destination_dir.$new_name;    $url = IMG_URL.$img_relat_path;    //判斷資料庫中圖片是否存在    $sql="select url from file_url where md5 = '".$md5file."'";    $res=$db->getOne($sql);    if($res) {        echo $res['url'];        exit;     }             if(!move_uploaded_file ($files['tmp_name'], $img_abs_path)) {//上傳檔案        echo "上傳檔案失敗";exit;    }        //將圖片存入資料庫           $sql="insert into file_url(url,product,md5,create_time) values('".$url."','".$product."','".$md5file."','".$today."')";    $db->Execute($sql);    $db->CloseDB();    echo $url;?>



  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.