将文件上传到服务器而不使用表单? [英] 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.
我想要它,因为我有非常大量的文件要上传。
I want it because I have very large number of files to upload. And this should be automatic with cron jobs.
推荐答案
这是使用cURL文件上传的示例,您可以从: p>
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屋!
查看全文