0

I want to send file from local to remote server and after saving file to server I want to output the response. I am using cURL to send file.

Here is my code.

$target_url = 'https://example.com/accept.php';
$file_name_with_full_path = realpath('ss.zip');
$post = array('file' => new CurlFile($file_name_with_full_path, 'application/zip' /* MIME-Type */, 'ss.zip'));

    $ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);
curl_close ($ch);
echo $result;

code on server is like:

$uploaddir = realpath('./') . '/';
$uploadfile = $uploaddir . basename($_FILES['file']['name']);
echo '<pre>';
    if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
        echo "File is valid, and was successfully uploaded.\n";
    }
    print_r($_FILES);
print "</pr" . "e>\n";

I don't know what's wrong with my code ? everytime it returns result false

Snappy
  • 203
  • 4
  • 18

0 Answers0