不使用表单将文件上传到服务器? [英] upload a file to server without using a form?
本文介绍了不使用表单将文件上传到服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们想象那种形式;
<form action="http://api.blabla.com/huhu.php" method="post" enctype="multipart/form-data">
<input type="file" name="files[]" />
<button type="submit">submit</button>
</form>
我想在不使用上面的表单的情况下将文件上传到此服务器.
I want to upload files to this server without using the form which is above.
我用 php curl 试过这个,但我不能.
I tried this with php curl but I could not.
我想要它,因为我有大量的文件要上传.这对于 cron 作业应该是自动的.
I want it because I have very large number of files to upload. And this should be automatic with cron jobs.
推荐答案
这是一个使用 cURL 上传文件的例子,你可以从:
This is an example of file uploading with cURL you could start with:
$ch = curl_init('http://api.blabla.com/huhu.php');
curl_setopt_array($ch, array(
CURLOPT_POSTFIELDS => array(
'files[]' => '@/path/to/file',
),
));
if (false === ($res = curl_exec($ch))) {
die("Upload failed: " . curl_error($ch));
}
字符串'@/path/to/file'
具有特殊意义,因为它以@
开头;紧随其后的字符串应包含您要上传的文件的路径.
The string '@/path/to/file'
has a special meaning because it starts with an @
; the string that directly follows it should contain the path of a file you wish to upload.
这篇关于不使用表单将文件上传到服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文