亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

是否可以通過來自 $_FILES 的 Angular 9 中的 http 請求訪問上傳的文件?

是否可以通過來自 $_FILES 的 Angular 9 中的 http 請求訪問上傳的文件?

PHP
UYOU 2023-04-28 17:19:29
我正在嘗試通過 angular 9 中的 http 請求將文件上傳到 php 服務器,但服務器無法在 $_FILES 中接收上傳的文件。我寫的代碼有點像:HTML:<input type="file"  (change)="detectFiles($event)" name="testFile" >PHP:<?php    header("Access-Control-Allow-Origin: *");     header('Access-Control-Allow-Credentials: true');    header("Access-Control-Allow-Methods: PUT, GET, POST, DELETE");    header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");    echo json_encode($_FILES['testFile']['name']);?>打字稿:detectFiles(event) {   const file = event.target.files[0];   this.httpClient.post<any>('http://localhost/test/uploadFile.php', file )     .subscribe( (response) => { console.log('uploading is done: ' + response); },                 (error) => { console.log('ERR during the uploading: ' + error); }     );}當我上傳文件時,我收到以下消息: 上傳期間出錯:[object Object]。有沒有可能從服務器端的 $_FILES 到達上傳的文件?提前致謝。
查看完整描述

1 回答

?
慕仙森

TA貢獻1827條經驗 獲得超8個贊

將您的文件附加到Formdata并發送


detectFiles(event) {

   var formData = new FormData();

   formData.append("file", event.target.files[0]);  

   this.httpClient.post<any>('http://localhost/test/uploadFile.php', formData)

     .subscribe( (response) => { console.log('uploading is done: ' + response); },

                 (error) => { console.log('ERR during the uploading: ' + error); }  

   );

}


查看完整回答
反對 回復 2023-04-28
  • 1 回答
  • 0 關注
  • 122 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號