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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用vue axios和PHP上傳多個(gè)文件 - 只上傳一個(gè)文件

使用vue axios和PHP上傳多個(gè)文件 - 只上傳一個(gè)文件

慕姐8265434 2023-08-05 19:26:33
我正在嘗試使用 vue 和 axios 創(chuàng)建多個(gè)文件上傳。我的問題是只有ine 文件會(huì)上傳到服務(wù)器。這是我使用的代碼:模板代碼<input type="file" name="images[]" multiple ref="images" @change="handleUpload()">JS代碼//this is part of the handleUpload() vue method.let formData = new FormData();for(let i;i < $refs.images.files.length; i++){ let file = this.$refs.images.files[i]; formData.append('image', file);}axios.post('/upload', formData, { header: { 'Content-Type': 'multipart/form-data' } }).then( (response) => console.log(response, response.data) ).catch( (error) => console.log(error) ); PHP服務(wù)器代碼// I'm using slim 4 and sirius upload to manage the file validation/uploaduse Psr\Http\Message\ResponseInterface as Response;use Psr\Http\Message\ServerRequestInterface as Request;use Psr\Http\Message\UploadedFileInterface;use Slim\Factory\AppFactory;use Sirius\Upload\Handler as UploadHandler;require __DIR__ . '/vendor/autoload.php';$app = AppFactory::create();$app->post('/platform/api/v1/compress', function(Request $request, Response $response){    $uploadHandler = new UploadHandler('/uploads');            $uploadHandler->addRule('extension', ['allowed' => ['jpg', 'jpeg', 'png']]);           $result = $uploadHandler->process( $request->getUploadedFiles() );                // handle single input with single file upload        if( $result->isValid() ){            $result->confirm();                               $url = ["master_image_url" => "/uploads/".$result->name];            $response->getBody()->write(json_encode($url));        }    return $response;});$app->run();如何上傳多個(gè)文件?也許我需要修改代碼?
查看完整描述

1 回答

?
慕田峪4524236

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超5個(gè)贊

append嘗試將函數(shù)中的“image”更改為“image[]”


例子:


for(let i;i < $refs.images.files.length; i++){

 let file = this.$refs.images.files[i];

 formData.append('image[]', file);

}

在服務(wù)器中


$uploadedFiles=$request->getUploadedFiles();

foreach ($uploadedFiles['image'] as $uploadedFile) {

        if ($uploadedFile->getError() === UPLOAD_ERR_OK) {

           

        }

    }


查看完整回答
反對(duì) 回復(fù) 2023-08-05
  • 1 回答
  • 0 關(guān)注
  • 172 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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