Cześć,
napisałem działający kod:
curl.php
/**
* @author aras785
* @param string $url
* @param array $data
* @param string $referer
* @return string
*/
function sendPostDataUsingCurl
(string
$url, array $data, string
$referer): string
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');
curl_setopt($ch, CURLOPT_TIMEOUT, 40000);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Referer: ' . $referer, 'Content-Type' => 'multipart/form-data']);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
$file = new CurlFile('zdjecie.jpg');
echo sendPostDataUsingCurl
('https:/example.com/index.php', ['image' => $file], 'https://wp.pl');
oraz standardowy formularz ze strony (https://www.tutorialspoint.com/php/php_file_uploading):
index.php:
<?php
if(isset($_FILES['image'])){ $file_name = $_FILES['image']['name'];
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
$extensions= array("jpeg","jpg","png");
if(in_array($file_ext,$extensions)=== false){ $errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if($file_size > 2097152){
$errors[]='File size must be excately 2 MB';
}
if(empty($errors)==true){ }else{
}
}
?>
<html>
<body>
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="image" />
<input type="submit"/>
</form>
</body>
</html>
U mnie ładnie się wrzuca, daj znać czy u Ciebie działa.
Pozdrawiam