I am trying to upload from one project folder to another project folder using CURL , but its not working . 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:
echo $encoded_file = $_POST['file'];exit;
so the scripts end on this line, hence no file is saved.