我想使用cURL上传文件.由于cURL需要文件的完整路径,所以这是我的代码:
curl_setopt($ch, CURLOPT_POSTFIELDS, array("submit" => "submit", "file" => "@path/to/file.ext"));
curl_exec($ch);
Run Code Online (Sandbox Code Playgroud)
但是,cURL还会在请求标头中发布该文件的完整路径:
内容处理:表格数据; NAME = "文件"; 文件名= "/路径/到/ file.ext"
但我希望它只是
内容处理:表格数据; NAME = "文件"; 文件名= "file.ext"
所以我将代码更改为
curl_setopt($ch, CURLOPT_POSTFIELDS, array("submit" => "submit", "file" => "@file.ext"));
chdir("path/to"); # change current working directory to where the file is placed
curl_exec($ch);
chdir("path"); # change current working directory back
Run Code Online (Sandbox Code Playgroud)
然后cURL只会抛出一条错误消息
无法打开文件"file.ext"
有人能告诉我怎么做吗?