将带有 CURL 的文件上传到网站

Flo*_*ian 5 post curl cmd batch-file

我尝试在 Windows CMD 上使用 cURL 将文件上传到网站。html 代码如下所示:

<form enctype="multipart/form-data" action="/Filebrowser?Path=/S71500/" method="POST" onsubmit="return checkUploadFile()">
<td><input id="filebrowser_upload_filename" type="file" name="filename" size="30" maxlength="80" style="background-color: transparent;"></td>
<td><input type="submit" value="Datei laden"></td> 
</form>
Run Code Online (Sandbox Code Playgroud)

我使用的命令是:

curl -F "filename=@/Users/Me/FILE.so" http://localhost:8080
Run Code Online (Sandbox Code Playgroud)

失败消息是:

Warning: setting file FILE.so failed!
curl: (26) read function returned funny value
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

小智 5

对我来说,这是一个权限问题。Curl 无法读取我的文件,因为它不可读。尝试:

sudo chmod a+r /path/to/your/file
Run Code Online (Sandbox Code Playgroud)

另外,请确保验证您是以 root 用户身份还是以文件所有者身份登录

ls -l /path/to/your/file
Run Code Online (Sandbox Code Playgroud)

将为您提供有关权限、所有权和组的信息,例如:

-rw-r--r-- 1 me users 792139 Jul  2 11:23 file.txt
Run Code Online (Sandbox Code Playgroud)

file.txt 可由 root、"me" 和组 "users" 的成员读取 - 只能由 root 写入,任何人都不能执行。它包含 792139 个字节


小智 -3

您应该将 PHP 代码放置在服务器的根目录中,如下所示

上传.php

<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['filename']['name']); 
if(move_uploaded_file($_FILES['filename']['tmp_name'], $target_path)) {
echo "The file ".  basename( $_FILES['filename']['name']). 
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
Run Code Online (Sandbox Code Playgroud)

请记住,您必须使用大写 F(表示形式)参数。小写 f 表示失败