簡單的php檔案上傳。乙個檔案搞定。

2021-06-18 19:34:12 字數 1403 閱讀 8900

把下面**另存為uploads.php 然後放在www目錄即可

<?

/* * uploads.php

* @name: simeple php file upload && download tool

* @author: rainysia

* @version: version 1.0

* @createtime: 2013-09-17 23:31:02

* @lastchange: 2013-10-17 15:55:40

*/function file_list($dir,$pattern="")

$tmp=realpath($dir.'/'.$file);

if(is_dir($tmp))

} else

}} closedir($dir_handle);

} return $arr;

}$d_root = $_server['document_root'];

$store_dir = "$d_root/uploads/";// 上傳檔案的儲存位置

if (!is_dir($store_dir))

$file_arr = file_list($store_dir);

foreach ($file_arr as $v=>$k)

$upload_file=isset($_files['upload_file']['tmp_name'])?$_files['upload_file']['tmp_name']:'';

$upload_file_name=isset($_files['upload_file']['name'])?$_files['upload_file']['name']:'';

$upload_file_size=isset($_files['upload_file']['size'])?$_files['upload_file']['size']:'';

if($upload_file)

$accept_overwrite = 1;//是否允許覆蓋相同檔案

// 檢查檔案大小

if ($upload_file_size > $file_size_max)

// 檢查讀寫檔案

if (file_exists($store_dir . $upload_file_name) && !$accept_overwrite)

//複製檔案到指定目錄

if (!move_uploaded_file($upload_file,$store_dir.$upload_file_name))

}if (isset($_files['upload_file']))

echo "";

}?>

PHP的乙個簡單的檔案上傳功能

檔案上傳使用的是move uploaded file 函式,使用array push 函式向陣列中新增元素,使用array unique 函式刪除陣列中的重複元素,使用array pop 函式獲取陣列中最後乙個元素,並將陣列長度減1,使用count 函式獲取陣列的元素個數。主要 頁面 width 檔...

PHP簡單檔案上傳

乙個簡單的php上傳檔案的例子 upload.html html body form action upload.php method post enctype multipart form data label for file filename label input type file nam...

PHP簡單的檔案上傳

首先判斷檔案是否已上傳到臨時目錄 if is array file 判斷檔案是否上傳到臨時目錄成功 switch file error 判斷檔案型別是否是 if in array file type allow 判斷檔案的大小是否在允許的範圍內 if file size size 檔案轉移 if m...