Why an empty request to the photo field?

Does not load photos on a server VC as path is not correct

// Function API call
 function by($method, $array = false) {
 $response = curl("https://api.vk.com/method/".$method, $array);
 $json = json_decode($response, true);
 if($json["error"]["error_msg"]) {
 return $json["error"];
 } else {
 return $json["response"];
}
}

// The function save the picture to the server 
 function download($picture = null, $group = null) {
 global $token, $group_post;
 $pic = curl_init($picture);
 $file = fopen("image.jpg", "wb");
 curl_setopt($pic, CURLOPT_FILE, $file);
 curl_setopt($pic, CURLOPT_HEADER, 0);
curl_exec($pic);
curl_close($pic);
 $getWallUploadServer = by("photos.getWallUploadServer", array("group_id" => $group_post, "access_token" => $token));
 $upload = curl($getWallUploadServer["upload_url"], array("file1" => "@".dirname(__FILE__)."/image.jpg"));
 $json = json_decode($upload, true);
 $saveWallPhoto = by("photos.saveWallPhoto", array("group_id" => $group_post, "photo" => $json["photo"], "hash" => $json["hash"], "server" => $json["server"], "access_token" => $token));
 return $saveWallPhoto[0]["id"];
}


 function curl($url, $post = false) {
 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
 curl_setopt($ch, THIS, false);
 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4 AlexaToolbar/alxg-3.1');
 if ($post) { 
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
 $response = curl_exec($ch);
curl_close($ch);
 return $response;
 }


This code path works like this
/home/q/m95351vh/site.ru/public_html/script/tools/image.jpg


How to specify the path correctly, if my image is located at this path
/home/q/m95351vh/site.ru/public_html/script/image.jpg


And why I have an empty photo

print_r($saveWallPhoto);

(
 [error_code] => 100
 [error_msg] => One of the parameters specified was missing or invalid: photos_list is invalid
 [request_params] => Array
(
 [0] => Array
(
 [key] => oauth
 [value] => 1
)

 [1] => Array
(
 [key] => method
 [value] => photos.saveWallPhoto
)

 [2] => Array
(
 [key] => group_id
 [value] => 55555552
)

 [3] => Array
(
 [key] => photo
 [value] => []
)

 [4] => Array
(
 [key] => hash
 [value] => c5775a11191e58052774f89f3556775d
)

 [5] => Array
(
 [key] => server
 [value] => 740460
)

)

)
June 8th 19 at 17:11
1 answer
June 8th 19 at 17:13
$file = fopen("image.jpg", "wb");
you will discover if only the picture is the same deer that the AI script itself. So it is better not to specify the path. Build off of
$_SERVER['DOCUMENT_ROOT'] . '/script/tools/image.jpg' ;

Again, this path is also undesirable
dirname(__FILE__)."/image.jpg"
how to alter this path dirname(__FILE__)."/image.jpg"
VK the picture at all and not see so - ludie commented on June 8th 19 at 17:16
Array
(
 [error_code] => 100
 [error_msg] => One of the parameters specified was missing or invalid: photos_list is invalid
 [request_params] => Array
(
 [0] => Array
(
 [key] => oauth
 [value] => 1
)

 [1] => Array
(
 [key] => method
 [value] => photos.saveWallPhoto
)

 [2] => Array
(
 [key] => group_id
 [value] => 71359952
)

 [3] => Array
(
 [key] => photo
 [value] => []
)

 [4] => Array
(
 [key] => hash
 [value] => 9e0c8da37b6dd9c2e1a91d5f245ae58e
)

 [5] => Array
(
 [key] => server
 [value] => 840629
)

)

)


Gives a picture not see - ludie commented on June 8th 19 at 17:19
also, using the full path of dir-s site
$_SERVER['DOCUMENT_ROOT'] . '/script/tools/image.jpg' ;
- earnest_Murazik75 commented on June 8th 19 at 17:22

Find more questions by tags PHP