The task is to upload an image to an album through Vkontakte API. Using the working example, https://ru.stackoverflow.com/a/492049/176892 tried to reproduce in his:
<? $img_real_path = '/home/***/docs/wp-content/uploads/gigapixel/preview.jpg'; //$img_real_path = '/home/***/docs/wp-content/themes/videodessa/shareimg.php'; $curl_file = curl_file_create($img_real_path,'image/jpg','test_name.jpg'); $ch=curl_init(); curl_setopt_array($ch, array( CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $_POST['upload_url'], CURLOPT_POST => 1, CURLOPT_POSTFIELDS => array("photo" => $curl_file), CURLOPT_HTTPHEADER => array('Content-Type: multipart/form-data; charset=UTF-8') )); echo curl_exec($ch); ?> Everything works, the file is poured. But there is a nuance. It works only with live jpg. If you try to feed a picture that is generated via php
$img_real_path = '/home/***/docs/wp-content/themes/videodessa/shareimg.php'; everything is bad:
{"server":624829,"photo":"[]","hash":"09b3a913eea42395dfba724db3adef29f","__error":"[!files_saveAlbumPhotoStorageEngine(file:test_name.jpg, res:-1, descr:)]"} Just in case I attach the shareimg.php image generation script:
<? header("Content-type: image/jpg"); $x = $_GET['x']; $y = $_GET['y']; $size = 200; $fullImage = getimagesize("../../uploads/gigapixel/full.jpg"); $origImage = imagecreatefromjpeg("../../uploads/gigapixel/orig.jpg"); $origW = imagesx($origImage); $origH = imagesy($origImage); $deltaW = $origW / $fullImage[0]; $deltaH = $origH / $fullImage[1]; $newImage = imagecreatetruecolor($size, $size); imagecopyresampled($newImage, $origImage, 0, 0, $x*$deltaW-$size/2, $y*$deltaH-$size/2, $size, $size, $size, $size); return imagejpeg($newImage); ?> But there is an opinion that it is just a curl should be taught well. And in it, I'm not at all strong. Thank.