zey_ser
Новичок
Добрый день! При записи изображения, изображение сохраняется с размером = 0. При открытии изображения получаю
Файл curl_file2.php
Файл curl_file.php
Пробовал и через file_put_contents и через fwrite, результат одинаков. Подскажите как быть!Ошибка интерпретации файла изображения формата JPEG (Improper call to JPEG library in state 200)
Файл curl_file2.php
PHP:
$file = 'import_files_e3f04115-f54b-11de-bbf6-001d60b9486d_845b0960-b6ed-11e6-80f9-000c298f88bd.jpeg';
$image = imageupload($file, 'key', 'd41d8cd98f00b204e9800998ecf8427e');
echo var_dump(json_decode($image, true));
var_dump($image);
function imageupload($file, $name, $pass) {
$data = array('name' => 'ff', 'file' => '@/var/www/zooapi/export/files/' . $file);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://test/curl_file.php");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Для загрузки на php > 5.5
if (PHP_VERSION_ID > 505000) {
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_COOKIE, "$name=$pass");
if (curl_errno($ch))
{
// moving to display page to display curl errors
$response[] = curl_errno($ch) ;
$response[] = curl_error($ch);
}
else
{
//getting response from server
$response = curl_exec($ch);
curl_close($ch);
}
return $response;
}
PHP:
if ($_SERVER['REQUEST_METHOD'] == "POST") {
$json = array();
$data = file_get_contents("php://input");
$uplod_file = '/var/www/test/' . $_FILES['file']['name'];
// file_put_contents($uplod_file, $data);
if ($fp = fopen($uplod_file, "wb")) {
$result = fwrite($fp, $data);
if ($result === strlen($data)) {
chmod($uplod_file , 0664);
}
else {
$json['error'][] = 'Данные';
}
} else {
$json['error'][] = 'Открытие';
}
if (empty($json)) $json['success'] = 'Успено';
echo json_encode($json);
}