Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.
Please keep in mind:
walrock said:haci esta erpo aun haci me tira error y ya puse la 1.4 sino pasame tu msn por ahi es mas facil chateandoCode:Server define('DOM_SCRIPT', $_SERVER['SERVER_NAME']); define('PATH_SERVER', $_SERVER['/public_html/']);
define('PATH_SERVER', '/public_html/');
<?
/* -----------------------------------------
Chevereto - Script de hosting de imagenes
Nightly Build 1.4 (25/02/2009)
http://www.chevereto.com/
Released under the GPL 2.0
Copyright (C) 2008 by Rodolfo Berrios
<inbox at rodolfoberrios dot com>
----------------------------------------- */
// Lang
define('LANG', 'es'); // en - English, es - Español
// Adaptar segun la instalacion
define('URL_SCRIPT', 'http://apthost.comli.com/'); // Your new image hosting URL, like "http://mydomain.com/" or "http://mydomain.com/chevereto/"
define('PATH_SCRIPT', '/'); // Ruta relativa desde la carpera web hasta el script (pe: /public_html/chevereto/ -> "/chevereto/") (pe: /public_html/' -> "/" si lo corres en la root web)
define('APP_NAME', 'Animeparatodos Hosting'); // Your image hosting name
define('TAG_LINE', 'Image Hosting'); // Your tagline (for doctitles and logo)
// Si cambias esto deberas cambiar las carpetas fisicas
define('DIR_UP','up/');
define('DIR_IM','images/');
define('DIR_WORKING',DIR_UP.'working/');
define('DIR_TEMP',DIR_UP.'temp/');
define('DIR_TH','thumbs/');
// Configuraciones de imagenes
$max_mb = '2.0'; // Maximo tamaño de imagen (Mbytes)
$max_by = $max_mb*1048576; // Maximo tamaño de imagen en bytes)
$max_name = '10'; // Caracteres maximos (no incluye ext y ".")
$mini_ancho = '150'; // Ancho del thumb (pixels)
$mini_alto = '150'; // Alto del thumb (pixels)
$lowres = '16'; // Minimo ancho a redimensionar
$higres = '1280'; // Maximo ancho de redimension
// Configuracion espedifica
$lim_act = true; // true: Permite que se posten imagenes solo de tu DOM_SCRIPT - false: Permite que se suba desde cualquier parte (por ejemplo un formulario en un foro)
$debug_mode = false; // false: No muestra nada - cualquier otro valor mostrara los errores segun la config del servidor.
$cut_url = true; // true: Se cortan las URL (pe: TinyURL.com) - false: No se cortan las URL.
$cut_url_user = true; // Si $cut_url = true -> true: Permite a los usuarios elegir cortar url (preferencia) - false: No los deja establecer preferencia
$allow_over_resize = false; // true: peremite que se redimensione por sobre el ancho de la imagen - false: no redimensiona sobre el ancho de la imagen
// Upload por FTP, en algunas configuraciones no es necesario el $use_ftp, pero en la mayoria si (pe: cPanel)
$use_ftp = true; // true: usara ftp para subir los archivos - false: no usara ftp (usar si php tiene permisos o si se aplica chmod).
$ftp_host = ftp.apthost.comli.com; // Si no es igual a tu dom script entonces lo cambias.
$ftp_user = 'a1792941';
$ftp_pass = 'aca la pass';
?>
<?
/* -----------------------------------------
Chevereto - Script de hosting de imagenes
Nightly Build 1.4 (25/02/2009)
http://www.chevereto.com/
Released under the GPL 2.0
Copyright (C) 2008 by Rodolfo Berrios
<inbox at rodolfoberrios dot com>
----------------------------------------- */
// VERSION DEL SCRIPT
define('SC_VERSION','NB1.4_rev1');
// Server
define('DOM_SCRIPT', $_SERVER['SERVER_NAME']);
define('PATH_SERVER', '/public_html/');
// Config
require('config.php');
if ($debug_mode==false) {
error_reporting(0);
}
// DOCTITLE
define('ESP_TITULO',' | ');
// VARIABLES
$lup = $_FILES['fileup'];
$remota = $_POST['remota'];
$resizf = str_replace(' ', '', $_POST['resize']); // Resize via POST
$url = $_GET['url'];
$urlrez = $_GET['urlrez'];
$v = $_GET['v']; if ($v=='.htaccess') { unset($v); $v=''; }
$page = $_GET['p'];
$view_fld = $_GET['folder'];
$resizr = $_GET['ancho']; // Resize via GET
// LANGUAGE
include('lang/'.LANG.'.php');
if (LANG!=='es') { $lang = LANG; }
// DE DONDE VIENES?
$referer = parse_url($_SERVER['HTTP_REFERER']);
if (empty($referer['host']) && !isset($referer['host'])) {
$referido = DOM_SCRIPT;
} else {
$referido = $referer['host'];
}
if (isset($remota)) {
$ref3 = explode('?',$ref2); // img.godlike.cl?urlrez=http:
$refok = $ref3['0'];
} else {
$refok = $ref2;
}
// Limite de actividad
if (isset($lup) || isset($remota)) {
if ($referido !== DOM_SCRIPT && $lim_act==true) {
if (!isset($url)) {
echo '<div style="background: #F00; color: #FFF; font-family: Courier, monospace; font-weight: bold; padding: 1em; text-align: center;">'.ERROR_REF.'</div>';
die;
}
}
}
// EL REZ
if (isset($resizr)) {
$resize = str_replace(' ', '', $resizr);
} else {
$resize = str_replace(' ', '', $resizf);
}
// SET Modo default
$modo = 1;
// MANEJEMOS LA RUP
if (isset($url)) {
$rup = str_replace(' ', '', $url);
} else {
$rup = str_replace(' ', '', $remota);
}
// DETERMINAMOS QUE MOSTRAMOS Y HACEMOS
// 1 = Mostrar formulario.
// 2 = Muetsra el visualizador
// 3 = Sube un archivo
// 4 = muestra la pag del error de redimensionamiento
// 5 = Muestra una pag. estatica
// spit = devuelve los mensajes de error.
// Modo pagina
if (isset($page)) {
unset($modo);
$modo = 5;
// haga el switch
switch ($page) {
// Los errores
case '400':
$h1 = TITLE_400;
$explained = DESC_400;
break;
case '401':
$h1 = TITLE_401;
$explained = DESC_401;
break;
case '403':
$h1 = TITLE_403;
$explained = DESC_403;
break;
case '404':
$h1 = TITLE_404;
$explained = DESC_404;
break;
case '500':
$h1 = TITLE_500;
$explained = DESC_500;
case '503':
$h1 = TITLE_503;
$explained = DESC_503;
break;
// Los directorios
case 'up':
$h1 = TITLE_DIR_NO;
$explained = DESC_DIR_NO;
break;
case 'up/temp':
$h1 = TITLE_DIR_NO;
$explained = DESC_DIR_NO;
break;
case 'up/working':
$h1 = TITLE_DIR_NO;
$explained = DESC_DIR_NO;
break;
case 'images':
$h1 = TITLE_DIR_NO;
$explained = DESC_DIR_NO;
break;
default:
$h1 = TITLE_404;
$explained = DESC_404;
$page = 'generico';
break;
}
$titulo = $h1.ESP_TITULO;
}
// Si hay posteo / urleo
if (isset($lup) || isset($remota) || isset($url)) {
if ($lup[size] ==! null || !empty($remota) || !empty($url)) {
unset($modo);
$modo = 3;
} else {
unset($modo);
$modo = 1;
$spit = true;
$errormsg = FORM_INCOMPLETE;
$titulo = TITLE_FORM_INCOMPLETE.ESP_TITULO;
}
}
// SI HAY DOBLE POSTEO...
if (!empty($rup) && !empty($lup['type'])) {
unset($modo);
$modo = 1;
$spit = true;
$errormsg = DOBLE_POSTED;
$titulo = FATAL_ERROR_TITLE.ESP_TITULO;
}
// Si hay urlrez, seteamos el modo rr
if (isset($urlrez)) {
if (!empty($urlrez)) {
// veamos la extension...
$urlrez3 = substr($urlrez, -3);
if ($urlrez3=='jpg' || $urlrez3=='peg' || $urlrez3=='gif' || $urlrez3=='bmp' || $urlrez3=='png') {
unset($modo);
$modo = 'rr';
$titulo = ENTER_WIDTH.ESP_TITULO;
} else {
$spit = true;
$errormsg = INVALID_EXT;
$titulo = INVALID_TITLE.ESP_TITULO;
}
} else {
$spit = true;
$errormsg = NOTHING_TO_RESIZE;
$titulo = INPUT_ERROR.ESP_TITULO;
}
}
// Si hay V, seteamos el modo 2
if (isset($v)) {
if (!empty($v)) {
unset($modo);
$modo = 2;
$name = $v;
} else {
$spit = true;
$errormsg = NO_ID;
$titulo = NO_ID_TITLE.ESP_TITULO;
}
}
$string = $rup.$urlrez;
if (preg_match("@".DOM_SCRIPT."/(site-img|js)/@", $string)) {
unset($modo);
$modo = 1;
$spit = true;
$errormsg = NO_SELF_UPLOAD;
$titulo = CANT_UPLOAD_TITLE.ESP_TITULO;
}
/* HAGAMOS EL UPLOADING ---MODO 3--- */
if ($modo==3) {
// Primer filtro (LOCAL)
function checklocal($lup) {
if (preg_match("@image/(gif|pjpeg|jpeg|png|x-png|bmp)$@", $lup['type'])) { return true; }
if ($lup['size']<$max_by) { return true; }
return false;
}
// Filtro (REMOTO)
function checkremota($rup) {
if (!empty($rup)) {
$rup3 = substr($rup, -3);
if ($rup3=='bmp') {
return true;
} else {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$rup);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,100);
$result = curl_exec($ch);
$imgstr = imagecreatefromstring($result);
curl_close($ch);
if ($imgstr==true) {
return true;
}
imagedestroy($imgstr);
}
}
return false;
}
if (checklocal($lup) || checkremota($rup)) {
// FTP
if ($use_ftp==true) {
$FTP_connect = ftp_connect($ftp_host);
$FTP_login = ftp_login($FTP_connect, $ftp_user, $ftp_pass);
// Veamos si conectamos..
if (!$FTP_connect || !$FTP_login) {
echo '<div style="background: #F00; color: #FFF; font-family: Courier, monospace; font-weight: bold; padding: 1em; text-align: center;">'.CANT_RUN.'</div>';
die();
}
ftp_pasv($FTP_connect, true);
ftp_chdir($FTP_connect, PATH_SERVER);
}
// LA SUBIDA LOCAL
if ($lup['size'] ==! null) {
if ($use_ftp==true) {
ftp_put($FTP_connect, './'.DIR_WORKING.$lup['name'], $lup['tmp_name'], FTP_BINARY);
} else {
copy($lup['tmp_name'], DIR_WORKING.$lup['name']);
}
$tmp_name = $lup[name]; // Temp name
}
// LA SUBIDA REMOTA
if (!empty($rup)) {
// Veamos si viene del resize
$grabname = substr("$rup", -21); // up/temp/000000000.jpg
if (file_exists($grabname)) {
$tmp_name = substr("$rup", -13);
rename($grabname, DIR_WORKING.$tmp_name);
} else {
// GET A NAME
$partes = explode('/', $rup);
$rname = $partes[count($partes) - 1];
// Conectando
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$rup);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
set_time_limit(300); // 5 Min. PHP
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,300); // 5 Min.cURL
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; es-ES; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6');
$rup_parse = parse_url($rup);
$rup_temp = substr($rup_parse['path'], 1);
if (preg_match("@".DIR_TEMP."@", $rup_temp)) {
$delete_temp = true;
}
if ($use_ftp==true) {
ftp_put($FTP_connect, DIR_WORKING.$rname, 'site-img/canvas.gif', FTP_BINARY);
ftp_chmod($FTP_connect, 0777, DIR_WORKING.$rname);
}
$out = fopen(DIR_WORKING.$rname, 'wb');
curl_setopt($ch, CURLOPT_FILE, $out);
// grab
$resultado = curl_exec($ch);
fclose($out);
curl_close($ch);
$tmp_name = $rname;
}
} // remota
// Manejemos la temporal
$handlework = DIR_WORKING.$tmp_name;
$info = getimagesize($handlework);
// Otras lecturas
$statinfo = @stat($handlework);
$tamano = $statinfo['size']; // BYTES
$tamano_kb = round($tamano/1024,2);
$mimosa = $info['mime']; // SI POR LA CONCHETUMADRE
$ancho = $info[0]; // Fijate en esto!
$alto = $info[1];
$mime = $info['mime'];
if (!$ancho || !$alto || !$mime || !$tamano) { // Fallan esas leseras
$invalida = true;
$inv_txt = INVALID_CORRUPT;
$no = true;
}
if ($tamano > $max_by) { // Muy pesada
$peso = true;
$no = true;
}
// Manejemos el mime tipe para los "amigos" que usan otras extensiones...
if ($mimosa=="image/gif") { $exten = 'gif'; }
if ($mimosa=="image/pjeg") { $exten = 'jpg'; }
if ($mimosa=="image/jpeg") { $exten = 'jpg'; }
if ($mimosa=="image/png") { $exten = 'png'; }
if ($mimosa=="image/bmp") { $exten = 'bmp'; }
if (!isset($no)) {
$up = true;
}
if ($no==true) {
// Eliminamos la imagen del up/working..
if ($use_ftp==true) {
ftp_delete($FTP_connect, $handlework);
} else {
unlink($handlework);
}
unset($modo);
$spit = true;
if ($peso==true) {
$pes_txt = TOO_HEAVY.' ('.$max_mb.'MB max.)';
}
if ($peso==true && $invalida==true) {
$ademas = ' '.ANDTEXT.' ';
}
} // no!
// Hay subida compadre...
if ($up) {
// Limpiemos el nombre
// --> Tambien me quedo "super rico".
$lower = strtolower($tmp_name); // Solo minusculas
$alnum = ereg_replace("[^[:alnum:]]","",$lower); // Solo alfanumericos
if ($exten==peg) { unset($exten); $exten = 'jpg'; }
$clear = substr_replace($alnum, '', -3); // sin extension ni punto
// Cortemos el nombre (si hace falta)
$conteo = strlen($clear);
// Random
$ch_1 = chr(rand(ord("a"), ord("z")));
$ch_2 = chr(rand(ord("z"), ord("a")));
if ($conteo>$max_name) {
$renombre = substr("$clear", 0, $max_name);
} else {
if (empty($clear)) {
$renombre = $ch_1.$ch_2.$ch_1;
} else {
$renombre = $clear;
}
}
// Si existe el nombre, renombramos el que estamos subiendo.
if (file_exists(DIR_IM.$renombre.'.'.$exten)) {
if ($conteo>$totalchars) {
// Si el nombre es muy largo, corta
$renombra = substr("$renombre", 0, $max_name-4); // 4 -> El remplazo de mas abajo
} else {
$renombra = $renombre;
}
// Vamos a darle caracteres aleatorios.
$name = $renombra.$ch_1.$ch_2.$ch_1.'.'.$exten;
} else {
$name = $renombre.'.'.$exten;
}
// Setiemos el redimensionamiento
if (!empty($resize)) {
if(preg_match("/[^0-9\.]/",$resize)) { // Queremos solo numeros!
$errormsg = JUST_NUMBERS;
$titulo = UPLOADED_BUT_NOT_RESIZED.ESP_TITULO;
$spit = true;
$red = 2;
} else {
if($allow_over_resize==false && $resize>$ancho) {
$errormsg = OVER_RESIZE_ERROR.' ('.$ancho.'px)';
$titulo = UPLOADED_BUT_NOT_RESIZED.ESP_TITULO;
$spit = true;
$red = 2;
} else {
if ($resize<=$higres && $resize>=$lowres) {
$new_alto = round($resize*$alto/$ancho);
// Seteamos el nuevo alto y ancho
unset($ancho);
unset($alto);
$ancho = $resize;
$alto = $new_alto;
$red = 1;
} else {
$errormsg = RESIZE_LIMITS.' '.$lowres.' '.ANDTEXT.' '.$higres.' (pixels)';
$titulo = UPLOADED_BUT_NOT_RESIZED.ESP_TITULO;
$spit = true;
$red = 2;
}
}
}
}
// Target -> Archivo a redimensionar (handlework)
// Archivo -> Archivo work (DIR_WORKING.$name)
function redimensionar($tipo,$target,$archivo,$ancho_n,$alto_n) {
global $use_ftp, $FTP_connect;
if ($tipo==gif) {
$src = imagecreatefromgif($target);
}
if ($tipo==png) {
$src = imagecreatefrompng($target);
}
if ($tipo==jpg) {
$src = imagecreatefromjpeg($target);
}
$era_x = imageSX($src);
$era_y = imageSY($src);
$destino = imagecreatetruecolor($ancho_n,$alto_n);
// gif
if ($tipo==gif) {
$transparente = imagecolortransparent($src);
imagepalettecopy($src, $destino);
imagefill($destino, 0, 0, $transparente);
imagecolortransparent($destino, $transparente);
imagetruecolortopalette($destino, true, 256);
} else {
imagecolortransparent($destino, imagecolorallocate($destino, 0, 0, 0) );
}
imagealphablending($destino, false);
imagesavealpha($destino, true);
imagecopyresampled($destino,$src,0,0,0,0,$ancho_n,$alto_n,$era_x,$era_y);
// Si esta por FTP, otorgar permiso
if ($use_ftp==true) { ftp_chmod($FTP_connect, 0777, PATH_SERVER.$archivo); }
if ($tipo==gif) { imagegif($destino, $archivo); }
if ($tipo==png) { imagepng($destino, $archivo); }
if ($tipo==jpg) { imagejpeg($destino, $archivo, 86); }
if ($tipo==bmp) { imagewbmp($destino, $archivo); }
imagedestroy($destino);
imagedestroy($src);
// Si esta por FTP, quitar permiso
if ($use_ftp==true) { ftp_chmod($FTP_connect, 0644, PATH_SERVER.$archivo); }
} // La funcion
if (empty($resize)) {
// Haga como si nada...
if ($use_ftp==true) {
ftp_put($FTP_connect, DIR_IM.$name, $handlework, FTP_BINARY); // COPIA -> ADONDE, QUEARCHIVO
ftp_put($FTP_connect, DIR_TH.$name, $handlework, FTP_BINARY); // Lo debemos hacer para que exista un archivo en thumbs para chmodear.
} else {
copy($handlework, DIR_IM.$name);
}
$titulo = UPLOAD_OK.ESP_TITULO;
}
if ($red==1) {
// Correr la funcion redimensionamiento *img en el working
if ($use_ftp==true) {
ftp_put($FTP_connect, DIR_WORKING.$name, $handlework, FTP_BINARY);
}
redimensionar($exten,$handlework,DIR_WORKING.$name,$ancho,$alto);
// Mover la redimensionada
if ($use_ftp==true) {
ftp_put($FTP_connect, DIR_IM.$name, DIR_WORKING.$name, FTP_BINARY);
ftp_put($FTP_connect, DIR_TH.$name, DIR_WORKING.$name, FTP_BINARY);
} else {
copy(DIR_WORKING.$name, DIR_IM.$name);
}
$titulo = UPLOAD_AND_RESIZED.ESP_TITULO;
// Borramos
if ($use_ftp==true) {
ftp_delete($FTP_connect, DIR_WORKING.$name);
if($delete_temp) { ftp_delete($FTP_connect, $rup_temp); }
} else {
unlink(DIR_WORKING.$name);
if($delete_temp==true) { unlink($rup_temp); }
}
}
if ($red==2) {
// No red correcto, renombra la temp (vea si esta)
$tname = DIR_TEMP.$name;
if (file_exists(DIR_TEMP.$name)) {
$numletra = ereg_replace("[^[:alnum:]]","",$name);
$cleartemp = substr_replace($numletra, '', -3); // sin extension ni punto
$randtemp = rand(000,999);
$tname = DIR_TEMP.$cleartemp.$randtemp.'.'.$exten;
} else {
$tname = DIR_TEMP.$name;
}
if ($use_ftp==true) {
ftp_put($FTP_connect, $tname, $handlework, FTP_BINARY);
} else {
rename($handlework, $tname);
}
$URLrdn = URL_SCRIPT.$tname;
// Setea el modo 4!
unset($modo);
$modo = 4;
}
// si se sube algo creemos el thumb
if ((empty($resize) || $red==1)) {
// thumb
if ($ancho>$alto) {
unset($mini_alto);
$mini_alto = round($mini_ancho*$alto/$ancho);
}
if ($ancho<$alto) {
unset($mini_ancho);
$mini_ancho = round($mini_alto*$ancho/$alto);
}
// Thumb
redimensionar($exten,$handlework,DIR_TH.$name,$mini_ancho,$mini_alto);
// Chao work
if ($use_ftp==true) {
ftp_delete($FTP_connect, $handlework);
} else {
unlink($handlework);
}
}
}
} else { // Check local + remote
unset($modo);
$modo = 1;
$spit = true;
$errormsg = CRITIC_ERROR_INPUT;
$titulo = ERROR_UPLOADING.ESP_TITULO;
}
}
if ($modo==2 || $modo==3) {
// INFORMACION (ANCHO, ALTO y PESO)
if ($modo==2) {
if ($_GET['v']) {
$id = $_GET['v'];
$imagen = DIR_IM.$id;
if (file_exists($imagen)==true) {
$title = SEEING.' '.$id;
$titulo = $id.' '.AT.' ';
$info = getimagesize($imagen); //Obtenemos la informacion
$statinfo = @stat($imagen);
$ancho = $info[0];
$alto = $info[1];
$mime = $info['mime'];
$tamano = $statinfo['size']; //Bytes
$tamano_kb = round($tamano*0.0009765625, 2);
$canales = $info['channels'];
} else {
unset($modo);
$modo = 1;
$spit = true;
$errormsg = NOT_EXISTS;
$titulo = NOT_EXISTS_TITLE.ESP_TITULO;
}
}
}
// LAS URL
$URLimg = URL_SCRIPT.DIR_IM.$name;
$URLthm = URL_SCRIPT.DIR_TH.$name;
$URLvim = URL_SCRIPT.'?v='.$name;
$URLshr = $URLvim; // Para no cambiar mas abajo
$eu_img = urlencode($URLimg);
// SI esta habilitado cortar url.. hagamolo.
if ($cut_url==true) {
// La Fx para TinyURL
function cortar_url($url) {
$tiny = 'http://tinyurl.com/api-create.php?url='.$url;
$chtny = curl_init();
curl_setopt($chtny, CURLOPT_URL, $tiny);
curl_setopt($chtny, CURLOPT_RETURNTRANSFER, 1);
$TinyURL = curl_exec($chtny);
curl_close($chtny);
return $TinyURL;
}
// Si se da a elegir al usuario, cortemos si el quiere.
if ($cut_url_user==true) {
// El usuario quiere cortar url...
if (isset($_COOKIE['prefurl'])) {
$TinyURL = cortar_url($URLimg);
}
// Cortamos si o si ya que la prefencia es de script y no de usuario.
} else {
$TinyURL = cortar_url($URLimg);
}
}
}
// Esto debria preguntar si hay ftp abierto y ahi cerrar.
if ($use_ftp==true) {
ftp_close($FTP_connect);
}
if (!isset($titulo)) {
$titulo = WELCOME;
}
?>
<?
/* -----------------------------------------
Chevereto - Script de hosting de imagenes
Nightly Build 1.4 (25/02/2009)
http://www.chevereto.com/
Released under the GPL 2.0
Copyright (C) 2008 by Rodolfo Berrios
<inbox at rodolfoberrios dot com>
----------------------------------------- */
// Lang
define('LANG', 'es'); // en - English, es - Español
// Adaptar segun la instalacion
define('URL_SCRIPT', 'http://apthost.comli.com/'); // Your new image hosting URL, like "http://mydomain.com/" or "http://mydomain.com/chevereto/"
define('PATH_SCRIPT', '/'); // Ruta relativa desde la carpera web hasta el script (pe: /public_html/chevereto/ -> "/chevereto/") (pe: /public_html/' -> "/" si lo corres en la root web)
define('APP_NAME', 'Animeparatodos Hosting'); // Your image hosting name
define('TAG_LINE', 'Image Hosting'); // Your tagline (for doctitles and logo)
// Si cambias esto deberas cambiar las carpetas fisicas
define('DIR_UP','up/');
define('DIR_IM','images/');
define('DIR_WORKING',DIR_UP.'working/');
define('DIR_TEMP',DIR_UP.'temp/');
define('DIR_TH','thumbs/');
// Configuraciones de imagenes
$max_mb = '2.0'; // Maximo tamaño de imagen (Mbytes)
$max_by = $max_mb*1048576; // Maximo tamaño de imagen en bytes)
$max_name = '10'; // Caracteres maximos (no incluye ext y ".")
$mini_ancho = '150'; // Ancho del thumb (pixels)
$mini_alto = '150'; // Alto del thumb (pixels)
$lowres = '16'; // Minimo ancho a redimensionar
$higres = '1280'; // Maximo ancho de redimension
// Configuracion espedifica
$lim_act = true; // true: Permite que se posten imagenes solo de tu DOM_SCRIPT - false: Permite que se suba desde cualquier parte (por ejemplo un formulario en un foro)
$debug_mode = false; // false: No muestra nada - cualquier otro valor mostrara los errores segun la config del servidor.
$cut_url = true; // true: Se cortan las URL (pe: TinyURL.com) - false: No se cortan las URL.
$cut_url_user = true; // Si $cut_url = true -> true: Permite a los usuarios elegir cortar url (preferencia) - false: No los deja establecer preferencia
$allow_over_resize = false; // true: peremite que se redimensione por sobre el ancho de la imagen - false: no redimensiona sobre el ancho de la imagen
// Upload por FTP, en algunas configuraciones no es necesario el $use_ftp, pero en la mayoria si (pe: cPanel)
$use_ftp = true; // true: usara ftp para subir los archivos - false: no usara ftp (usar si php tiene permisos o si se aplica chmod).
$ftp_host = 'apthost.comli.com'; // Si no es igual a tu dom script entonces lo cambias.
$ftp_user = 'a1792941';
$ftp_pass = 'aca la pass';
?>
<?
/* -----------------------------------------
Chevereto - Script de hosting de imagenes
Nightly Build 1.4 (25/02/2009)
http://www.chevereto.com/
Released under the GPL 2.0
Copyright (C) 2008 by Rodolfo Berrios
<inbox at rodolfoberrios dot com>
----------------------------------------- */
// VERSION DEL SCRIPT
define('SC_VERSION','NB1.4_rev1');
// Server
define('PATH_SERVER', '/public_html/');
// Config
require('config.php');
if ($debug_mode==false) {
error_reporting(0);
}
// DOCTITLE
define('ESP_TITULO',' | ');
// VARIABLES
$lup = $_FILES['fileup'];
$remota = $_POST['remota'];
$resizf = str_replace(' ', '', $_POST['resize']); // Resize via POST
$url = $_GET['url'];
$urlrez = $_GET['urlrez'];
$v = $_GET['v']; if ($v=='.htaccess') { unset($v); $v=''; }
$page = $_GET['p'];
$view_fld = $_GET['folder'];
$resizr = $_GET['ancho']; // Resize via GET
// LANGUAGE
include('lang/'.LANG.'.php');
if (LANG!=='es') { $lang = LANG; }
// DE DONDE VIENES?
$referer = parse_url($_SERVER['HTTP_REFERER']);
if (empty($referer['host']) && !isset($referer['host'])) {
$referido = DOM_SCRIPT;
} else {
$referido = $referer['host'];
}
if (isset($remota)) {
$ref3 = explode('?',$ref2); // img.godlike.cl?urlrez=http:
$refok = $ref3['0'];
} else {
$refok = $ref2;
}
// Limite de actividad
if (isset($lup) || isset($remota)) {
if ($referido !== DOM_SCRIPT && $lim_act==true) {
if (!isset($url)) {
echo '<div style="background: #F00; color: #FFF; font-family: Courier, monospace; font-weight: bold; padding: 1em; text-align: center;">'.ERROR_REF.'</div>';
die;
}
}
}
// EL REZ
if (isset($resizr)) {
$resize = str_replace(' ', '', $resizr);
} else {
$resize = str_replace(' ', '', $resizf);
}
// SET Modo default
$modo = 1;
// MANEJEMOS LA RUP
if (isset($url)) {
$rup = str_replace(' ', '', $url);
} else {
$rup = str_replace(' ', '', $remota);
}
// DETERMINAMOS QUE MOSTRAMOS Y HACEMOS
// 1 = Mostrar formulario.
// 2 = Muetsra el visualizador
// 3 = Sube un archivo
// 4 = muestra la pag del error de redimensionamiento
// 5 = Muestra una pag. estatica
// spit = devuelve los mensajes de error.
// Modo pagina
if (isset($page)) {
unset($modo);
$modo = 5;
// haga el switch
switch ($page) {
// Los errores
case '400':
$h1 = TITLE_400;
$explained = DESC_400;
break;
case '401':
$h1 = TITLE_401;
$explained = DESC_401;
break;
case '403':
$h1 = TITLE_403;
$explained = DESC_403;
break;
case '404':
$h1 = TITLE_404;
$explained = DESC_404;
break;
case '500':
$h1 = TITLE_500;
$explained = DESC_500;
case '503':
$h1 = TITLE_503;
$explained = DESC_503;
break;
// Los directorios
case 'up':
$h1 = TITLE_DIR_NO;
$explained = DESC_DIR_NO;
break;
case 'up/temp':
$h1 = TITLE_DIR_NO;
$explained = DESC_DIR_NO;
break;
case 'up/working':
$h1 = TITLE_DIR_NO;
$explained = DESC_DIR_NO;
break;
case 'images':
$h1 = TITLE_DIR_NO;
$explained = DESC_DIR_NO;
break;
default:
$h1 = TITLE_404;
$explained = DESC_404;
$page = 'generico';
break;
}
$titulo = $h1.ESP_TITULO;
}
// Si hay posteo / urleo
if (isset($lup) || isset($remota) || isset($url)) {
if ($lup[size] ==! null || !empty($remota) || !empty($url)) {
unset($modo);
$modo = 3;
} else {
unset($modo);
$modo = 1;
$spit = true;
$errormsg = FORM_INCOMPLETE;
$titulo = TITLE_FORM_INCOMPLETE.ESP_TITULO;
}
}
// SI HAY DOBLE POSTEO...
if (!empty($rup) && !empty($lup['type'])) {
unset($modo);
$modo = 1;
$spit = true;
$errormsg = DOBLE_POSTED;
$titulo = FATAL_ERROR_TITLE.ESP_TITULO;
}
// Si hay urlrez, seteamos el modo rr
if (isset($urlrez)) {
if (!empty($urlrez)) {
// veamos la extension...
$urlrez3 = substr($urlrez, -3);
if ($urlrez3=='jpg' || $urlrez3=='peg' || $urlrez3=='gif' || $urlrez3=='bmp' || $urlrez3=='png') {
unset($modo);
$modo = 'rr';
$titulo = ENTER_WIDTH.ESP_TITULO;
} else {
$spit = true;
$errormsg = INVALID_EXT;
$titulo = INVALID_TITLE.ESP_TITULO;
}
} else {
$spit = true;
$errormsg = NOTHING_TO_RESIZE;
$titulo = INPUT_ERROR.ESP_TITULO;
}
}
// Si hay V, seteamos el modo 2
if (isset($v)) {
if (!empty($v)) {
unset($modo);
$modo = 2;
$name = $v;
} else {
$spit = true;
$errormsg = NO_ID;
$titulo = NO_ID_TITLE.ESP_TITULO;
}
}
$string = $rup.$urlrez;
if (preg_match("@".DOM_SCRIPT."/(site-img|js)/@", $string)) {
unset($modo);
$modo = 1;
$spit = true;
$errormsg = NO_SELF_UPLOAD;
$titulo = CANT_UPLOAD_TITLE.ESP_TITULO;
}
/* HAGAMOS EL UPLOADING ---MODO 3--- */
if ($modo==3) {
// Primer filtro (LOCAL)
function checklocal($lup) {
if (preg_match("@image/(gif|pjpeg|jpeg|png|x-png|bmp)$@", $lup['type'])) { return true; }
if ($lup['size']<$max_by) { return true; }
return false;
}
// Filtro (REMOTO)
function checkremota($rup) {
if (!empty($rup)) {
$rup3 = substr($rup, -3);
if ($rup3=='bmp') {
return true;
} else {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$rup);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,100);
$result = curl_exec($ch);
$imgstr = imagecreatefromstring($result);
curl_close($ch);
if ($imgstr==true) {
return true;
}
imagedestroy($imgstr);
}
}
return false;
}
if (checklocal($lup) || checkremota($rup)) {
// FTP
if ($use_ftp==true) {
$FTP_connect = ftp_connect($ftp_host);
$FTP_login = ftp_login($FTP_connect, $ftp_user, $ftp_pass);
// Veamos si conectamos..
if (!$FTP_connect || !$FTP_login) {
echo '<div style="background: #F00; color: #FFF; font-family: Courier, monospace; font-weight: bold; padding: 1em; text-align: center;">'.CANT_RUN.'</div>';
die();
}
ftp_pasv($FTP_connect, true);
ftp_chdir($FTP_connect, PATH_SERVER);
}
// LA SUBIDA LOCAL
if ($lup['size'] ==! null) {
if ($use_ftp==true) {
ftp_put($FTP_connect, './'.DIR_WORKING.$lup['name'], $lup['tmp_name'], FTP_BINARY);
} else {
copy($lup['tmp_name'], DIR_WORKING.$lup['name']);
}
$tmp_name = $lup[name]; // Temp name
}
// LA SUBIDA REMOTA
if (!empty($rup)) {
// Veamos si viene del resize
$grabname = substr("$rup", -21); // up/temp/000000000.jpg
if (file_exists($grabname)) {
$tmp_name = substr("$rup", -13);
rename($grabname, DIR_WORKING.$tmp_name);
} else {
// GET A NAME
$partes = explode('/', $rup);
$rname = $partes[count($partes) - 1];
// Conectando
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$rup);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
set_time_limit(300); // 5 Min. PHP
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,300); // 5 Min.cURL
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.0; es-ES; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6');
$rup_parse = parse_url($rup);
$rup_temp = substr($rup_parse['path'], 1);
if (preg_match("@".DIR_TEMP."@", $rup_temp)) {
$delete_temp = true;
}
if ($use_ftp==true) {
ftp_put($FTP_connect, DIR_WORKING.$rname, 'site-img/canvas.gif', FTP_BINARY);
ftp_chmod($FTP_connect, 0777, DIR_WORKING.$rname);
}
$out = fopen(DIR_WORKING.$rname, 'wb');
curl_setopt($ch, CURLOPT_FILE, $out);
// grab
$resultado = curl_exec($ch);
fclose($out);
curl_close($ch);
$tmp_name = $rname;
}
} // remota
// Manejemos la temporal
$handlework = DIR_WORKING.$tmp_name;
$info = getimagesize($handlework);
// Otras lecturas
$statinfo = @stat($handlework);
$tamano = $statinfo['size']; // BYTES
$tamano_kb = round($tamano/1024,2);
$mimosa = $info['mime']; // SI POR LA CONCHETUMADRE
$ancho = $info[0]; // Fijate en esto!
$alto = $info[1];
$mime = $info['mime'];
if (!$ancho || !$alto || !$mime || !$tamano) { // Fallan esas leseras
$invalida = true;
$inv_txt = INVALID_CORRUPT;
$no = true;
}
if ($tamano > $max_by) { // Muy pesada
$peso = true;
$no = true;
}
// Manejemos el mime tipe para los "amigos" que usan otras extensiones...
if ($mimosa=="image/gif") { $exten = 'gif'; }
if ($mimosa=="image/pjeg") { $exten = 'jpg'; }
if ($mimosa=="image/jpeg") { $exten = 'jpg'; }
if ($mimosa=="image/png") { $exten = 'png'; }
if ($mimosa=="image/bmp") { $exten = 'bmp'; }
if (!isset($no)) {
$up = true;
}
if ($no==true) {
// Eliminamos la imagen del up/working..
if ($use_ftp==true) {
ftp_delete($FTP_connect, $handlework);
} else {
unlink($handlework);
}
unset($modo);
$spit = true;
if ($peso==true) {
$pes_txt = TOO_HEAVY.' ('.$max_mb.'MB max.)';
}
if ($peso==true && $invalida==true) {
$ademas = ' '.ANDTEXT.' ';
}
} // no!
// Hay subida compadre...
if ($up) {
// Limpiemos el nombre
// --> Tambien me quedo "super rico".
$lower = strtolower($tmp_name); // Solo minusculas
$alnum = ereg_replace("[^[:alnum:]]","",$lower); // Solo alfanumericos
if ($exten==peg) { unset($exten); $exten = 'jpg'; }
$clear = substr_replace($alnum, '', -3); // sin extension ni punto
// Cortemos el nombre (si hace falta)
$conteo = strlen($clear);
// Random
$ch_1 = chr(rand(ord("a"), ord("z")));
$ch_2 = chr(rand(ord("z"), ord("a")));
if ($conteo>$max_name) {
$renombre = substr("$clear", 0, $max_name);
} else {
if (empty($clear)) {
$renombre = $ch_1.$ch_2.$ch_1;
} else {
$renombre = $clear;
}
}
// Si existe el nombre, renombramos el que estamos subiendo.
if (file_exists(DIR_IM.$renombre.'.'.$exten)) {
if ($conteo>$totalchars) {
// Si el nombre es muy largo, corta
$renombra = substr("$renombre", 0, $max_name-4); // 4 -> El remplazo de mas abajo
} else {
$renombra = $renombre;
}
// Vamos a darle caracteres aleatorios.
$name = $renombra.$ch_1.$ch_2.$ch_1.'.'.$exten;
} else {
$name = $renombre.'.'.$exten;
}
// Setiemos el redimensionamiento
if (!empty($resize)) {
if(preg_match("/[^0-9\.]/",$resize)) { // Queremos solo numeros!
$errormsg = JUST_NUMBERS;
$titulo = UPLOADED_BUT_NOT_RESIZED.ESP_TITULO;
$spit = true;
$red = 2;
} else {
if($allow_over_resize==false && $resize>$ancho) {
$errormsg = OVER_RESIZE_ERROR.' ('.$ancho.'px)';
$titulo = UPLOADED_BUT_NOT_RESIZED.ESP_TITULO;
$spit = true;
$red = 2;
} else {
if ($resize<=$higres && $resize>=$lowres) {
$new_alto = round($resize*$alto/$ancho);
// Seteamos el nuevo alto y ancho
unset($ancho);
unset($alto);
$ancho = $resize;
$alto = $new_alto;
$red = 1;
} else {
$errormsg = RESIZE_LIMITS.' '.$lowres.' '.ANDTEXT.' '.$higres.' (pixels)';
$titulo = UPLOADED_BUT_NOT_RESIZED.ESP_TITULO;
$spit = true;
$red = 2;
}
}
}
}
// Target -> Archivo a redimensionar (handlework)
// Archivo -> Archivo work (DIR_WORKING.$name)
function redimensionar($tipo,$target,$archivo,$ancho_n,$alto_n) {
global $use_ftp, $FTP_connect;
if ($tipo==gif) {
$src = imagecreatefromgif($target);
}
if ($tipo==png) {
$src = imagecreatefrompng($target);
}
if ($tipo==jpg) {
$src = imagecreatefromjpeg($target);
}
$era_x = imageSX($src);
$era_y = imageSY($src);
$destino = imagecreatetruecolor($ancho_n,$alto_n);
// gif
if ($tipo==gif) {
$transparente = imagecolortransparent($src);
imagepalettecopy($src, $destino);
imagefill($destino, 0, 0, $transparente);
imagecolortransparent($destino, $transparente);
imagetruecolortopalette($destino, true, 256);
} else {
imagecolortransparent($destino, imagecolorallocate($destino, 0, 0, 0) );
}
imagealphablending($destino, false);
imagesavealpha($destino, true);
imagecopyresampled($destino,$src,0,0,0,0,$ancho_n,$alto_n,$era_x,$era_y);
// Si esta por FTP, otorgar permiso
if ($use_ftp==true) { ftp_chmod($FTP_connect, 0777, PATH_SERVER.$archivo); }
if ($tipo==gif) { imagegif($destino, $archivo); }
if ($tipo==png) { imagepng($destino, $archivo); }
if ($tipo==jpg) { imagejpeg($destino, $archivo, 86); }
if ($tipo==bmp) { imagewbmp($destino, $archivo); }
imagedestroy($destino);
imagedestroy($src);
// Si esta por FTP, quitar permiso
if ($use_ftp==true) { ftp_chmod($FTP_connect, 0644, PATH_SERVER.$archivo); }
} // La funcion
if (empty($resize)) {
// Haga como si nada...
if ($use_ftp==true) {
ftp_put($FTP_connect, DIR_IM.$name, $handlework, FTP_BINARY); // COPIA -> ADONDE, QUEARCHIVO
ftp_put($FTP_connect, DIR_TH.$name, $handlework, FTP_BINARY); // Lo debemos hacer para que exista un archivo en thumbs para chmodear.
} else {
copy($handlework, DIR_IM.$name);
}
$titulo = UPLOAD_OK.ESP_TITULO;
}
if ($red==1) {
// Correr la funcion redimensionamiento *img en el working
if ($use_ftp==true) {
ftp_put($FTP_connect, DIR_WORKING.$name, $handlework, FTP_BINARY);
}
redimensionar($exten,$handlework,DIR_WORKING.$name,$ancho,$alto);
// Mover la redimensionada
if ($use_ftp==true) {
ftp_put($FTP_connect, DIR_IM.$name, DIR_WORKING.$name, FTP_BINARY);
ftp_put($FTP_connect, DIR_TH.$name, DIR_WORKING.$name, FTP_BINARY);
} else {
copy(DIR_WORKING.$name, DIR_IM.$name);
}
$titulo = UPLOAD_AND_RESIZED.ESP_TITULO;
// Borramos
if ($use_ftp==true) {
ftp_delete($FTP_connect, DIR_WORKING.$name);
if($delete_temp) { ftp_delete($FTP_connect, $rup_temp); }
} else {
unlink(DIR_WORKING.$name);
if($delete_temp==true) { unlink($rup_temp); }
}
}
if ($red==2) {
// No red correcto, renombra la temp (vea si esta)
$tname = DIR_TEMP.$name;
if (file_exists(DIR_TEMP.$name)) {
$numletra = ereg_replace("[^[:alnum:]]","",$name);
$cleartemp = substr_replace($numletra, '', -3); // sin extension ni punto
$randtemp = rand(000,999);
$tname = DIR_TEMP.$cleartemp.$randtemp.'.'.$exten;
} else {
$tname = DIR_TEMP.$name;
}
if ($use_ftp==true) {
ftp_put($FTP_connect, $tname, $handlework, FTP_BINARY);
} else {
rename($handlework, $tname);
}
$URLrdn = URL_SCRIPT.$tname;
// Setea el modo 4!
unset($modo);
$modo = 4;
}
// si se sube algo creemos el thumb
if ((empty($resize) || $red==1)) {
// thumb
if ($ancho>$alto) {
unset($mini_alto);
$mini_alto = round($mini_ancho*$alto/$ancho);
}
if ($ancho<$alto) {
unset($mini_ancho);
$mini_ancho = round($mini_alto*$ancho/$alto);
}
// Thumb
redimensionar($exten,$handlework,DIR_TH.$name,$mini_ancho,$mini_alto);
// Chao work
if ($use_ftp==true) {
ftp_delete($FTP_connect, $handlework);
} else {
unlink($handlework);
}
}
}
} else { // Check local + remote
unset($modo);
$modo = 1;
$spit = true;
$errormsg = CRITIC_ERROR_INPUT;
$titulo = ERROR_UPLOADING.ESP_TITULO;
}
}
if ($modo==2 || $modo==3) {
// INFORMACION (ANCHO, ALTO y PESO)
if ($modo==2) {
if ($_GET['v']) {
$id = $_GET['v'];
$imagen = DIR_IM.$id;
if (file_exists($imagen)==true) {
$title = SEEING.' '.$id;
$titulo = $id.' '.AT.' ';
$info = getimagesize($imagen); //Obtenemos la informacion
$statinfo = @stat($imagen);
$ancho = $info[0];
$alto = $info[1];
$mime = $info['mime'];
$tamano = $statinfo['size']; //Bytes
$tamano_kb = round($tamano*0.0009765625, 2);
$canales = $info['channels'];
} else {
unset($modo);
$modo = 1;
$spit = true;
$errormsg = NOT_EXISTS;
$titulo = NOT_EXISTS_TITLE.ESP_TITULO;
}
}
}
// LAS URL
$URLimg = URL_SCRIPT.DIR_IM.$name;
$URLthm = URL_SCRIPT.DIR_TH.$name;
$URLvim = URL_SCRIPT.'?v='.$name;
$URLshr = $URLvim; // Para no cambiar mas abajo
$eu_img = urlencode($URLimg);
// SI esta habilitado cortar url.. hagamolo.
if ($cut_url==true) {
// La Fx para TinyURL
function cortar_url($url) {
$tiny = 'http://tinyurl.com/api-create.php?url='.$url;
$chtny = curl_init();
curl_setopt($chtny, CURLOPT_URL, $tiny);
curl_setopt($chtny, CURLOPT_RETURNTRANSFER, 1);
$TinyURL = curl_exec($chtny);
curl_close($chtny);
return $TinyURL;
}
// Si se da a elegir al usuario, cortemos si el quiere.
if ($cut_url_user==true) {
// El usuario quiere cortar url...
if (isset($_COOKIE['prefurl'])) {
$TinyURL = cortar_url($URLimg);
}
// Cortamos si o si ya que la prefencia es de script y no de usuario.
} else {
$TinyURL = cortar_url($URLimg);
}
}
}
// Esto debria preguntar si hay ftp abierto y ahi cerrar.
if ($use_ftp==true) {
ftp_close($FTP_connect);
}
if (!isset($titulo)) {
$titulo = WELCOME;
}
?>