Ok i was wondering if it is possible to use curl and upload a image from my sites directory rather then off my machine, what i need to do exactly is upload a image from my image directory using the file-select in a form, If anyone knows what i need to edit in my code i would appreciate it, i have looked across the web but found nothing in my search, I was thinking that i would need to file get content base64 encode then post am i right in thinking this?
$upload_url = 'http://example.com/settings/upload-img';
$file_path = 'directory/image.png';
$fields = array(
"MAX_FILE_SIZE" => "",
"fileselect[]" => $file_path
);
foreach ($fields as $key => $val) {
$post_data .= $key . '=' . $val . '&';
}
$chr = curl_init();
curl_setopt($chr, CURLOPT_URL, $upload_url);
curl_setopt($chr,CURLOPT_POST, count($fields));
curl_setopt($chr,CURLOPT_POSTFIELDS, rtrim($post_data, '&'));
curl_setopt($chr, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($chr);
curl_close($chr);
What I had in mind for the image to base64_encode() is below, I am not sure if I am correct thinking this may work.
$raw_img = base64_encode(file_get_contents('directory/image.png'));
Then use "fileselect[]" => $raw_img