Created
September 24, 2015 08:53
-
-
Save anonymous/f3d8d8814ad74da0e823 to your computer and use it in GitHub Desktop.
fixes remote upload errors in Code Future Image host 0.6.5 for http://jesusfuck.me and others
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/************************************************************************************************************** | |
* | |
* CF Image Hosting Pro | |
* --------------------------------- | |
* | |
* Author: codefuture.co.uk | |
* Version: 0.4.5 | |
* | |
* You can download the latest version from: http://codefuture.co.uk/projects/imagehost/ | |
* | |
* Copyright (c) 2010-2013 CodeFuture.co.uk | |
* This file is part of the CF Image Hosting Script. | |
* | |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | |
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | |
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF | |
* OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
* | |
* | |
* You may not modify and/or remove any copyright notices or labels on the software on each | |
* page (unless full license is purchase) and in the header of each script source file. | |
* | |
* You should have received a full copy of the LICENSE AGREEMENT along with | |
* Codefuture Image Hosting Script. If not, see http://codefuture.co.uk/projects/imagehost/license/. | |
* | |
* | |
* ABOUT THIS PAGE ----- | |
* Used For: Image Upload Code | |
* Last edited: 28/01/2013 | |
* | |
*************************************************************************************************************/ | |
if(!defined('cfih')) define('cfih', 'upload'); | |
require_once './inc/cfih.php'; | |
// check to see if upload has been disable (set in the admin panel), if so then send user to the index/home page | |
if($settings['SET_DIS_UPLOAD']){ | |
if(!checklogin()){ | |
header('Location: index.php'); | |
exit(); | |
} | |
} | |
// set time out timer to 10mins | |
ini_set("max_execution_time", "600"); | |
ini_set("max_input_time", "600"); | |
// drag and drop upload | |
if(isset($_POST['ajaxupload']) && $_POST['ajaxupload']){ | |
if(isset($_SESSION['upload']) AND count($_SESSION['upload']) >= $settings['SET_MAX_UPLOAD']) exit; | |
$api_upload = 1; | |
$format = 'txt'; | |
usleep(100000); | |
} | |
//unset session | |
if(!isset($_POST['ajaxupload']) || !$_POST['ajaxupload']) unset($_SESSION['upload']); | |
unset($_SESSION['err']); | |
//////////////////////////////////////////////////////////////////////////////////// | |
// UPLOAD CODE START | |
//testing | |
$settings['SET_ALLOW_ANIMATION'] = false;// true; | |
// see if user is banned | |
if (db_isBanned()){ | |
user_feedback('error',_T("site_upload_banned"),'Banned'); | |
} | |
// check for image file or url | |
if((!isset($_POST['imgUrl']) || empty($_POST['imgUrl'])) && (!isset($_FILES['files']) || $_FILES['files']['error'][0] > 0)){ | |
user_feedback('error',_T("site_upload_err_no_image"),'NoImage'); | |
} | |
if(($_SERVER['REQUEST_METHOD'] == 'POST' || isset($admin_upload)) && !isset($_SESSION['err']) || isset($_SERVER['HTTP_X_FILENAME'])){ | |
// what source | |
$source = isset($_POST['imgUrl']) && !empty($_POST['imgUrl'])?$_POST['imgUrl']:$_FILES['files']; | |
$is_remote = false; | |
if (isset($_POST['imgUrl'])) { | |
$is_remote = true; | |
} | |
// setup upload class | |
require CFLIBPATH.'upload.class.php'; | |
$imgUp = new upload($source); | |
$imgUp->set_memory_limit($IMG_MEMORY_LIMIT); | |
$imgUp->set_tweak_factor($IMG_TWEAK_FACTOR); | |
$imgUp->set_accepted_formats($acceptedFormats); | |
$imgUp->set_max_filesize($settings['SET_MAXSIZE']); // in bits | |
$imgUp->set_min_dimensions($IMG_MIN_SIZE); // pixels | |
$imgUp->set_max_dimensions($IMG_MAX_SIZE); // pixels | |
$imgUp->set_upload_dir(CFIMAGEPATH); | |
$imgUp->set_temp_dir(CFIMGTEMPPATH); | |
$imgUp->set_allow_animation($settings['SET_ALLOW_ANIMATION']); | |
$imgUp->set_id_length($IMG_ID_LENGTH); | |
$imgCount = 0; // used to limit uploads | |
$number_of_uploads = !isset($_POST['imgUrl']) || empty($_POST['imgUrl'])?count($_FILES['files']['name']):1; | |
error_log($is_remote, 3, "/var/log/apache2/errortest.log"); | |
error_log("TEST", 3, "/var/log/apache2/errortest.log"); | |
for($i=0; $i < $number_of_uploads;++$i){ | |
if(!$imgUp->process($i, $is_remote)){ | |
if($imgUp->error_code == 110) user_feedback('error',$imgUp->info['full_name'].' - '._T("site_upload_url_err_no_image"),'image_404'); | |
if($imgUp->error_code == 120) user_feedback('error',$imgUp->info['full_name'].' - '._T("site_upload_types_accepted",implode(", ",$imgFormats)),'extension'); | |
if($imgUp->error_code == 121) user_feedback('error',$imgUp->info['full_name'].' - '._T("site_upload_to_small",$IMG_MIN_SIZE.'x'.$IMG_MIN_SIZE),'sizetosmall'); | |
if($imgUp->error_code == 122) user_feedback('error',$imgUp->info['full_name'].' - '._T("site_upload_to_big",$IMG_MAX_SIZE.'x'.$IMG_MAX_SIZE),'sizetobig'); | |
if($imgUp->error_code == 123) user_feedback('error',$imgUp->info['full_name'].' - '._T("site_upload_size_accepted",format_size($settings['SET_MAXSIZE'])),'filetobig'); | |
if($imgUp->error_code == 124) user_feedback('error',$imgUp->info['full_name'].' - '._T("site_upload_opening_image"),'opening'); | |
continue; | |
} | |
$imgUp->fingerprint(); | |
// need to check for duplicate images? | |
if($settings['SET_NODUPLICATE']){ | |
//check for Duplicate Images | |
if($fp=db_find_fingerprint($imgUp->info['fingerprint'])){ | |
// If similar files exist, check them | |
foreach($fp as $fpItem){ | |
if ($imgUp->are_duplicates(imageAddress(1,$fpItem))){ | |
$dupFound = true; | |
$dup = $fpItem; | |
break; | |
} | |
} | |
if(isset($dupFound)){ | |
$err_add = '<br/><a href="'.imageAddress(2,$dup,'pm').'" title="'.$dup['img_alt'].'" >Duplicate Images</a>'; | |
user_feedback('error','<b>'.$imgUp->info['full_name'].'</b> '._T("upload_duplicate_found").' '.$err_add,'duplicate '); | |
continue; | |
} | |
} | |
} | |
if(!$imgUp->finish_upload((isset($admin_upload)?1:null))){ | |
if($imgUp->error_code == 125) user_feedback('error','<b>'.$imgUp->info['full_name'].'</b> '._T("site_upload_err").' .','filemove'); | |
continue; | |
} | |
//Resize image if needed | |
if ($settings['SET_RESIZE_IMG_ON']) { | |
if((isset($_POST['new_width'][$i]) && !empty($_POST['new_width'][$i])) || | |
(isset($_POST['new_height'][$i]) && !empty($_POST['new_height'][$i]))){ | |
$imgUp->stretchSmallImages(true); | |
if(!empty($_POST['new_width'][$i]) && !empty($_POST['new_height'][$i])){ | |
$imgUp->resizeImage($_POST['new_width'][$i], $_POST['new_height'][$i], 'exact'); | |
} | |
elseif(!empty($_POST['new_width'][$i]) && empty($_POST['new_height'][$i])){ | |
$imgUp->resizeImage($_POST['new_width'][$i], $imgUp->info['width'], 'landscape'); | |
} | |
elseif(empty($_POST['new_width'][$i]) && !empty($_POST['new_height'][$i])){ | |
$imgUp->resizeImage($imgUp->info['height'], $_POST['new_height'][$i], 'portrait'); | |
} | |
$imgUp->saveImage($imgUp->info['address'],100,null,true); | |
$imgUp->info['size'] = filesize($imgUp->info['address']); // get new image file size | |
$imgUp->stretchSmallImages(false); // set it back to false | |
} | |
} | |
// check for theme Settings | |
$THUMB_OPTION = theme_setting('thumb_option',$THUMB_OPTION); | |
$THUMB_MAX_WIDTH = theme_setting('thumb_max_width',$THUMB_MAX_WIDTH); | |
$THUMB_MAX_HEIGHT = theme_setting('thumb_max_height',$THUMB_MAX_HEIGHT); | |
// make thumb | |
$thumb_mid_address = CFTHUMBPATH.$imgUp->info['new']; | |
$imgUp -> resizeImage($THUMB_MID_MAX_WIDTH, $THUMB_MID_MAX_HEIGHT, $THUMB_MID_OPTION); | |
$imgUp -> saveImage($thumb_mid_address, ($imgUp->info['ext'] == 'png'?$PNG_QUALITY:$JPG_QUALITY)); | |
// make small thumb | |
$thumb_address = CFSMALLTHUMBPATH.$imgUp->info['new']; | |
$imgUp -> resizeImage($THUMB_MAX_WIDTH, $THUMB_MAX_HEIGHT, $THUMB_OPTION); | |
$imgUp -> saveImage($thumb_address, ($imgUp->info['ext'] == 'png'?$PNG_QUALITY:$JPG_QUALITY)); | |
$image = $imgUp->info; | |
$imgUp->destroyImage(); | |
$image['alt'] = removeSymbols(cl(!empty($_POST['alt'][$i])?$_POST['alt'][$i]:$image['name'])); | |
//see if thumb's got made | |
if(!file_exists($thumb_address) || !file_exists($thumb_mid_address)){ | |
@unlink($image['address']); | |
@unlink($thumb_address); | |
@unlink($thumb_mid_address); | |
user_feedback('error','<b>'.$image['name'].'</b> '._T("site_upload_err").' ..','thumbmade'); | |
continue; | |
} | |
// see if we need to get a short url for the image | |
$shorturl = null; | |
if (isset($_POST['shorturl'][$i]) && $_POST['shorturl'][$i] == 1 && $settings['SET_SHORT_URL_ON']){ | |
$shorturl = shorturl_url('http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).'?di='.$image['id']); | |
} | |
// get thumb's file size | |
$thumbsize = filesize($thumb_mid_address); | |
$sthumbsize = filesize($thumb_address); | |
$image['album'] = isset($_POST['album_id'][$i])?(int)$_POST['album_id'][$i]:1; | |
// Make image info array to save to db | |
$newImageArray = array( 'img_id' => $image['id'], | |
'img_name' => $image['full_name'], | |
'img_alt' => $image['alt'], | |
'img_added' => date("Y-m-d H:i:s",time()), | |
'img_ext' => $image['ext'], | |
'img_upload_ip' => $_SERVER['REMOTE_ADDR'], | |
'img_size' => $image['size'], | |
'img_delete_id' => $image['did'], | |
'img_thumb_size' => $thumbsize, | |
'img_small_thumb_size'=> $sthumbsize, | |
'img_is_private' => (isset($_POST['private'][$i])?1:0), | |
'img_report' => 0, | |
'img_shorturl' => (!isset($shorturl)?null:$shorturl), | |
'img_width' => $image['width'],//$imgSize[0], | |
'img_height' => $image['height'],//$imgSize[1], | |
'img_fingerprint' => $image['fingerprint'], | |
'album_id' => $image['album'] | |
); | |
//save new image to database | |
if(db_add_image($newImageArray)){ | |
// save image to upload array to be sent to thumb page | |
$_SESSION['upload'][] = array('id' => $image['id'],'did' => $image['did']); | |
$imgApiArray = array( | |
'img_name' => $newImageArray['img_name'], | |
'img_page' => imageAddress(2,$newImageArray,'pm'), | |
'img_url' => imageAddress(1,$newImageArray,'di'), | |
'img_width' => $newImageArray['img_width'], | |
'img_height' => $newImageArray['img_height'], | |
'img_bytes' => $newImageArray['img_size'], | |
'img_delete_id' => $newImageArray['img_delete_id'], | |
'thumb_url' => imageAddress(2,$newImageArray,'dm'), | |
'thumb_small_url' => imageAddress(3,$newImageArray,'dt') | |
); | |
// count images uploaded | |
$imgCount++; | |
if($imgCount >= $settings['SET_MAX_UPLOAD'] && !isset($admin_upload)){ | |
break; // break upload loop as you have updated max number of images in one go... | |
} | |
}else{ | |
user_feedback('error','<b>'.$image['name'].'</b> '._T("site_index_delete_image_err_db"),'savedb'); | |
continue; | |
} | |
}// end image upload loop | |
} | |
// error uploading image | |
elseif(!isset($_SESSION['err'])){ | |
user_feedback('error',_T("site_upload_err").' ...','unknown_error'); | |
} | |
// remove temp images | |
if(isset($removeList)){ | |
foreach ($removeList as $tempImg){ | |
// remove old file | |
if(file_exists($tempImg)){ | |
unlink($tempImg); | |
} | |
} | |
} | |
//////////////////////////////////////////////////////////////////////////////////// | |
// send to page | |
// API output | |
if(isset($api_upload) && $format!=='redirect'){ | |
// check for errors | |
if(!isset($_SESSION['err']) && isset($imgApiArray['img_url']) ) { | |
$REST_API['status_code'] = 200; | |
$REST_API['status_txt'] = 'OK'; | |
$api_txt_output = $imgApiArray['img_url']; | |
$REST_API['data'] = $imgApiArray; | |
} | |
// upload error | |
else { | |
// image format | |
if(isset($_SESSION['err']['extension'])) { | |
$REST_API['status_code'] = 3; | |
$REST_API['status_txt'] = _T("api_bad_formats"); | |
} | |
// image size | |
if(isset($_SESSION['err']['filesize'])) { | |
$REST_API['status_code'] = 4; | |
$REST_API['status_txt'] = _T("api_too_large"); | |
} | |
//An unkown error occured | |
else{ | |
$REST_API['status_code'] = 403; | |
$REST_API['status_txt'] = $_SESSION['err'][key($_SESSION['err'])]; | |
} | |
$api_txt_output = $REST_API['status_code'].' - '.$REST_API['status_txt']; | |
} | |
$OUTPUT_REST_API = array_filter($REST_API); | |
switch($format) { | |
case 'xml': | |
xml_output($OUTPUT_REST_API);break; | |
case 'txt': | |
echo $api_txt_output;break; | |
case 'json': | |
default: | |
json_output($OUTPUT_REST_API, $callback);break; | |
} | |
unset($_SESSION['err']); | |
exit; | |
} | |
// admin bulk uploader | |
if(isset($admin_upload)){ | |
header('Location: '. $settings['SET_SITEURL'].'admin.php?act=bulk'); | |
exit(); | |
} | |
// error send back to home page and show the error | |
if(!isset($_SESSION['upload'])){ | |
header('Location: '. $settings['SET_SITEURL'].'index.php'); | |
exit(); | |
} | |
// open thumb page and show upload images | |
header('Location: '. $settings['SET_SITEURL'].'thumbnail.php'); | |
die(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment