0

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>

cURL 页面如下所示:

<?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 如下所示:

<?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!";
}
?>

这甚至接近工作吗?

4

0 回答 0