function imageeditor_upload in Image Editor 6
Same name and namespace in other branches
- 7 imageeditor.pages.inc \imageeditor_upload()
1 string reference to 'imageeditor_upload'
- imageeditor_menu in ./
imageeditor.module - Implementation of hook_menu().
File
- ./
imageeditor.module, line 248 - Allows online editing of images using different image editing services.
Code
function imageeditor_upload($service = '', $request = '') {
if ($service == 'pixlr_upload' || $service == 'immio_upload') {
$filepath = '@' . $_SERVER['DOCUMENT_ROOT'] . '/' . $_GET['filepath'];
}
elseif ($service == 'imageshack_upload') {
//Imageshack needs mimetype to be added
$type = file_get_mimetype($_GET['filepath']);
$filepath = '@' . $_SERVER['DOCUMENT_ROOT'] . '/' . $_GET['filepath'] . ';type=' . $type;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_POST, true);
if ($service == 'pixlr_upload') {
curl_setopt($ch, CURLOPT_URL, 'http://pixlr.com/store/');
$post = array(
'image' => $filepath,
);
}
elseif ($service == 'immio_upload') {
curl_setopt($ch, CURLOPT_URL, 'http://imm.io/store/');
$post = array(
'image' => $filepath,
);
}
elseif ($service == 'imageshack_upload') {
curl_setopt($ch, CURLOPT_URL, 'http://www.imageshack.us/upload_api.php');
$post = array(
'fileupload' => $filepath,
'key' => variable_get('imageeditor_imageshack_api_key', ''),
'xml' => 'yes',
);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
curl_close($ch);
if ($service == 'pixlr_upload') {
print 'http://pixlr.com/_temp/' . $response;
exit;
}
elseif ($service == 'immio_upload') {
$result = json_decode($response, TRUE);
if ($result['success']) {
print $result['payload']['uri'];
}
else {
print $result['payload'];
}
exit;
}
elseif ($service == 'imageshack_upload') {
$xml = simplexml_load_string($response);
if ($xml) {
if (isset($xml->error)) {
print $xml->error;
}
else {
print $xml->links->image_link;
}
}
exit;
}
}