duandang2123 2019-01-02 19:31
浏览 52

通过发布请求传输文件

i am pretty new to php. I am trying to upload a file. And its working. But now I am trying to make a POST request via C# (does not depend on C#, the error must be somewhere in my php code) and its not working. The Response/Error says:

Undefined index: fileToUpload in <b>C:\xampp\htdocs\subdir\process.php</b> on line <b>8</

line 8 for example is $target_file = $target_dir . rand() .basename($_FILES["fileToUpload"]["name"]);

I checked the request header with fiddler when I upload the file successfully via the website but I am not getting any information that could help me.

Fiddler Raw Request Header:

POST /subdir/process.php HTTP/1.1
Host: localhost
Connection: keep-alive
Content-Length: 45551695
Cache-Control: max-age=0
Origin: http://localhost
Upgrade-Insecure-Requests: 1
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryepwGfigXDyjxAtPu
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3650.1 Iron Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
Referer: http://localhost/subdir/upload.php
Accept-Encoding: gzip, deflate, br
Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7

Upload.php:

<form action="process.php" method="post" enctype="multipart/form-data">
    <b>Select file to upload:</b><br><br>
    <input type="file" name="fileToUpload" id="fileID"><br>
    <input type="submit" value="Upload file" name="submit">
</form>

Process.php:

header("Content-type: text/plain");
$target_dir = "uploads/";
$target_file = $target_dir . rand() .basename($_FILES["fileToUpload"]["name"]);

if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
    echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
    echo "Sorry, there was an error uploading your file. 
Error Code:". $_FILES["fileToUpload"]['error'];
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 set_link_state
    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度