我正在尝试使用CURL从一个项目文件夹上传到另一个项目文件夹,但它无法正常工作。谁能建议我?
下面我发布了我的代码
此代码位于一个项目文件夹中。
<form enctype="multipart/form-data" encoding='multipart/form-data' method='post' action="form.php">
<input name="uploadedfile" type="file" value="choose">
<input type="submit" value="Upload">
</form>
<?
//echo "<pre>";print_r($_FILES['uploadedfile']);
if (isset($_FILES['uploadedfile']['name']) && $_FILES['uploadedfile']['name']!="") {
$filename = $_FILES['uploadedfile']['tmp_name'];
$handle = fopen($filename, "r");
$data = fread($handle, filesize($filename));
$POST_DATA = array(
'file' => base64_encode($data)
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://localhost/curl_image_server/handle.php');
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $POST_DATA);
$response = curl_exec($curl);
curl_close ($curl);
echo "<h2>File Uploaded</h2>";
}
?>
此代码位于另一个项目文件夹
中<?php
echo $encoded_file = $_POST['file'];
$decoded_file = base64_decode($encoded_file);
/* Now you can copy the uploaded file to your server. */
file_put_contents('subins', $decoded_file);
?>
答案 0 :(得分:0)
嗯,你在这一行的末尾打电话给exit()
:
echo $encoded_file = $_POST['file'];exit;
所以脚本在这一行结束,因此没有保存文件。