php中的多文件上傳我想上傳多個文件并將它們存儲在一個文件夾中,獲取路徑并將其存儲在數據庫中.任何你想要做多個文件上傳的好例子.。注:文件可以是任何類型的.。
3 回答
神不在的星期二
TA貢獻1963條經驗 獲得超6個贊
輸入名稱必須定義為數組,即 name="inputName[]"輸入元素必須具有 multiple="multiple"或者只是 multiple在PHP文件中使用語法 "$_FILES['inputName']['param'][index]"確保尋找 空文件名和路徑
,數組可能包含 空字符串
..使用 array_filter()在數數之前。
<input name="upload[]" type="file" multiple="multiple" />
//$files = array_filter($_FILES['upload']['name']); //something like that to be used before processing files.
// Count # of uploaded files in array$total = count($_FILES['upload']['name']);// Loop through each filefor( $i=0 ; $i < $total ; $i++ ) {
//Get the temp file path
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
//Make sure we have a file path
if ($tmpFilePath != ""){
//Setup our new file path
$newFilePath = "./uploadFiles/" . $_FILES['upload']['name'][$i];
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $newFilePath)) {
//Handle other code here
}
}}
江戶川亂折騰
TA貢獻1851條經驗 獲得超5個贊
<input type='file' name='file[]' multiple>
<html><title>Upload</title><?php
session_start();
$target=$_POST['directory'];
if($target[strlen($target)-1]!='/')
$target=$target.'/';
$count=0;
foreach ($_FILES['file']['name'] as $filename)
{
$temp=$target;
$tmp=$_FILES['file']['tmp_name'][$count];
$count=$count + 1;
$temp=$temp.basename($filename);
move_uploaded_file($tmp,$temp);
$temp='';
$tmp='';
}
header("location:../../views/upload.php");?></html>$_FILES['file']['name'][0]$_FILES['file']['name'][1]
- 3 回答
- 0 關注
- 446 瀏覽
添加回答
舉報
0/150
提交
取消
