第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

php中的多文件上傳

php中的多文件上傳

PHP
梵蒂岡之花 2019-06-12 21:34:26
php中的多文件上傳我想上傳多個文件并將它們存儲在一個文件夾中,獲取路徑并將其存儲在數(shù)據(jù)庫中.任何你想要做多個文件上傳的好例子.。注:文件可以是任何類型的.。
查看完整描述

3 回答

?
神不在的星期二

TA貢獻1963條經(jīng)驗 獲得超6個贊

我知道這是一篇老文章,但對那些試圖上傳多個文件的人來說,進一步的解釋可能會有幫助.下面是你需要做的事情:

  • 輸入名稱必須定義為數(shù)組,即

    name="inputName[]"

  • 輸入元素必須具有

    multiple="multiple"

    或者只是

    multiple

  • 在PHP文件中使用語法

    "$_FILES['inputName']['param'][index]"

  • 確保尋找

    空文件名和路徑

    ,數(shù)組可能包含

    空字符串

    ..使用

    array_filter()

    在數(shù)數(shù)之前。

下面是一個向下和骯臟的示例(只顯示相關(guān)代碼)

HTML:

<input name="upload[]" type="file" multiple="multiple" />

PHP:

//$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

    }
  }}

希望這能幫上忙!


查看完整回答
反對 回復(fù) 2019-06-12
?
江戶川亂折騰

TA貢獻1851條經(jīng)驗 獲得超5個贊

可以選擇多個文件,然后使用
<input type='file' name='file[]' multiple>
進行上傳的示例php腳本:

<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>

將選定的文件作為數(shù)組接收

$_FILES['file']['name'][0]存儲第一個文件的名稱。
$_FILES['file']['name'][1]存儲第二個文件的名稱。
諸若此類。


查看完整回答
反對 回復(fù) 2019-06-12
  • 3 回答
  • 0 關(guān)注
  • 435 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號