[英]Curl file upload from one project folder to another project folder is not working
I am trying to upload from one project folder to another project folder using CURL , but its not working . 我正在尝试使用CURL从一个项目文件夹上载到另一个项目文件夹,但是它不起作用。 Can anyone suggest me ? 有人可以建议我吗?
Below I am posting my codes 下面我发布我的代码
This code is in one project folder . 此代码在一个项目文件夹中。
<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>";
}
?>
This code is in another project folder 此代码在另一个项目文件夹中
<?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);
?>
Well, you are calling exit()
at the end of this line: 好吧,您在此行的结尾处调用exit()
:
echo $encoded_file = $_POST['file'];exit;
so the scripts end on this line, hence no file is saved. 因此脚本在此行结束,因此不会保存任何文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.