Php 通过cURL将文件获取到远程服务器时出现问题

Php 通过cURL将文件获取到远程服务器时出现问题,php,curl,Php,Curl,刚接触cURL的我在获取上传到远程服务器的文件时遇到了问题。我有一个.html文件,它有一个文件上传输入。然后,它进入带有cURL代码的.php,然后进入服务器 HTML如下所示: <form action="send.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id

刚接触cURL的我在获取上传到远程服务器的文件时遇到了问题。我有一个.html文件,它有一个文件上传输入。然后,它进入带有cURL代码的.php,然后进入服务器

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>
<?php
$curlPost = array('fileupload' => '@'.$_FILES['theFile'] ['tmp_name']);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://24.18.65.72:8008/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
$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!";
}
?>

文件名:

卷曲页面如下所示:

<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>
<?php
$curlPost = array('fileupload' => '@'.$_FILES['theFile'] ['tmp_name']);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://24.18.65.72:8008/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
$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!";
}
?>

远程服务器上的receiving.php如下所示:

<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>
<?php
$curlPost = array('fileupload' => '@'.$_FILES['theFile'] ['tmp_name']);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://24.18.65.72:8008/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
$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!";
}
?>


这是否已经接近成功了?

您是否得到了一些反馈?输出,或者可能是错误消息?为什么要使用cURL?您可以将HTML表单直接提交到处理upload.Tierre的PHP页面,当我点击submit时,它会进入带有cURL的.PHP页面,并在那里空白。在服务器端,我不确定在哪里检查错误。Nilpo,我尝试了完全相同的代码,但跳过了curl并将远程服务器目标添加到表单中的操作。我总是在if语句中得到“else”错误消息。您不是第一个提出这一建议的人,您是否发现了任何可能错误的地方或阻止了这一点?您是否检查了$folder=“files/”;是可写的吗?