I think it should work, but I get an Internal Server Error.
Here is the code:
Code: Select all
<?php
$msg = "";
switch(!strcasecmp($_SERVER['REQUEST_METHOD'], "POST")) {
case true:
if(!isset($_FILES['image']) || $_FILES['image'] == "none" || $_FILES['image'] == "") {
$msg = "<font color='#0000FF' size='1' face='Arial, Helvetica, sans-serif'>Seleccione sus fotografías pulsando -Examinar-</font>";
break;
}
$tmp = getcwd()."/".$_FILES['image']['name'];
if(!@move_uploaded_file($_FILES['image']['tmp_name'], $tmp)) {
$msg = "<font color='#0000FF' size='1' face='Arial, Helvetica, sans-serif'>Ha ocurrido un error al subir la imagen</font>";
break;
}
$fp = fopen($tmp, "rb");
$str = fread($fp, filesize($tmp));
fclose($fp);
unlink($tmp);
$im1 = ImageCreateFromString($str);
$base="mm";
$conexion=mysql_connect("mm","mm","mm");
mysql_select_db($base,$conexion);
$result = mysql_query("SELECT * FROM fotos");
$num_rows = mysql_num_rows($result);
$numref = ("$num_rows"+5001);
$iniciales = "rkf";
$Ref =$iniciales.$numref;
$sql = mysql_query("SELECT * FROM fotos WHERE ref2= '$Ref'");
while(mysql_num_rows($sql) != 0){
$Ref =$iniciales.($numref++);break;
}
$imgname = $Ref."thumb_1"; $maxwidth = 300;
$maxheight = 150;
$width1 = ImageSX($im1);
$height1 = ImageSY($im1);
$width2 = $maxwidth;
$height2 = floor(($width2 * $height1) / $width1);
if($maxheight > 0 && $height2 > $maxheight) {
$height2 = $maxheight;
$width2 = floor(($height2 * $width1) / $height1);
}
$im2 = ImageCreateTrueColor($width2, $height2);
ImageCopyResampled($im2, $im1, 0, 0, 0, 0, $width2, $height2, $width1, $height1);
ImageJpeg($im2, "thumb/".$imgname.".jpg"); // Se copia en temp/
$msg = "Ok";
$im3 = ImageCreateFromString($str);
$imgname2 = $Ref;
$maxwidth2 = 800;
$maxheight2 = 250;
$width12 = ImageSX($im3);
$height12= ImageSY($im3);
$width22 = $maxwidth2;
$height22 = floor(($width22 * $height12) / $width12);
if($maxheight2 > 0 && $height22 > $maxheight2) {
$height22 = $maxheight2;
$width22 = floor(($height22 * $width12) / $height12);
}
$im4 = ImageCreateTrueColor($width22, $height22);
ImageCopyResampled($im4, $im3, 0, 0, 0, 0, $width22, $height22, $width12, $height12);
ImageJpeg($im4, "full/".$imgname2.".jpg"); // Se copia en temp/
$sql2 = "INSERT INTO fotos (artista,banda,evento,fecha,fotografo,ciudad,ref_autor,recinto,ref2)".
"VALUES ('$artista','$banda','$evento','$fecha','$fotografo','$ciudad','$ref_autor','$recinto','$ref2')";
$result2 = mysql_query($sql2) or die(mysql_error().'<p>'.$sql2.'</p>');
$image_url = "http://www.mysite.com/full".$ref".jpg";
$size = getimagesize($image_url);
$imagewidth = $size[0]; // Index 0
// Asignando variables fijas
$font_file = $_SERVER[DOCUMENT_ROOT]."/images/fonts/verdana.TTF";
$font_size = 8;
$angle = 0;
$max_width = 300;
// Asignando texto
$texto = "www.mysite.com";
// Calculate horizontal starting point for the text (discussed in step 3)
$line_width = imagettfbbox($font_size, 0, $font_file, $texto);
if($pos==1){$x_start="10";$y_start="10";}else if
($pos==2){$x_start=($imagewidth-($line_width[2] - $line_width[0]));$y_start="10";}else if
($pos==3){$x_start="10";$y_start="230";}else if
($pos==4){$x_start=($imagewidth-($line_width[2] - $line_width[0]));$y_start="230";}
header("Content-type: image/jpeg");
$im = imagecreatefromJpeg("images/".$ref.".jpg");
$red = imagecolorallocate($color);
imagettftext($im, $font_size, $angle, $x_start, $y_start, $red, $font_file, $texto);
imagejpeg($im);
header("Location:../solo.php?fotoinsert=si");
break;
}
?>