Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
要发送到远程主机的PHP cURL安装程序_Php_Forms_Curl - Fatal编程技术网

要发送到远程主机的PHP cURL安装程序

要发送到远程主机的PHP cURL安装程序,php,forms,curl,Php,Forms,Curl,我有一些关于cURL的基本问题,我在cURL文档中找不到答案(可能是因为其他人都知道这些问题…)。我有一个表单中的文件类型输入,需要将该文件发送到远程服务器。cURL代码是与表单一起出现在页面上,还是表单发送给您的页面上的cURL,然后被发送到远程服务器 以下是html格式: <form action="send.php" method="post" enctype="multipart/form-data"> <label for="file">Filename

我有一些关于cURL的基本问题,我在cURL文档中找不到答案(可能是因为其他人都知道这些问题…)。我有一个表单中的文件类型输入,需要将该文件发送到远程服务器。cURL代码是与表单一起出现在页面上,还是表单发送给您的页面上的cURL,然后被发送到远程服务器

以下是html格式:

<form action="send.php" method="post" enctype="multipart/form-data">
    <label for="file">Filename:</label>
    <input type="file" name="file" id="file" /> 
    <br />
    <input type="submit" name="submit" value="Submit" />
</form>
在远程服务器上,我可以接收以下文件:

$folder = "files/";
$path = $folder . basename( $_FILES['file']['name']); 
if(move_uploaded_file($_FILES['file']['tmp_name'], $path)) {
    echo "The file ".  basename( $_FILES['file']['name']). " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

这有点近吗

您不需要从浏览器上传文件,您可以直接将表单提交到远程服务器进行上传-只需确保表单提交到任何包含第三段代码的文件即可

$curlPost = array('fileupload' => '@'.$_FILES['theFile'] ['tmp_name']);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://remoteServer/upload_file.php');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec();
curl_close($ch);
另一个例子

如何使用PHP cURL将图像文件上载到远程服务器


我试过了,每次都收到了错误信息。我在这里发布了一个关于它的问题,每个人都说要使用cURL或ftp。如果我要删除cURL,文件实际上是如何到达远程服务器的?您不需要使用cURL从浏览器接收文件上载。我正在查看链接,但我仍然不确定cURL代码去了哪里。看链接示例,我得到的印象是它在远程服务器上运行,对吗?
$curlPost = array('fileupload' => '@'.$_FILES['theFile'] ['tmp_name']);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://remoteServer/upload_file.php');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec();
curl_close($ch);