I have a php code who miniaturizes uploaded pictures by users.
This code is in the "miniature.php" file and it creates a file for each new picture.
After having uploaded the picture in another file (userform), it shows a preview (the miniature).
However, this is a dead link (I can see a little broken picture). The URL is like that :
http://www.mywebsite.com/annonce/miniature.php?pic=upload/XStmQFRY/PICTURE_UPLOADED.JPG&w_max=70&h_max=60
The url below, on the other hand, works and shows the original picture :
http://www.mywebsite.com/annonce/upload/XStmQFRY/PICTURE_UPLOADED.JPG
If you have an idea... do not hesitate!
Thank you :)
miniature.php code :
<?php
error_reporting(E_ALL ^ E_NOTICE);
$taille = getimagesize($pic);
$h_i = $taille[1];
$w_i = $taille[0];
if($h_i >$h_max)
{
$convert=$h_max/$h_i;
$h_i=$h_max;
$w_i=ceil($w_i*$convert);
}
if($w_i >$w_max)
{
$convert=$w_max/$w_i;
$w_i=$w_max;
$h_i=ceil($h_i*$convert);
} ;
$largeur = $w_i;
$hauteur = $h_i;
header("Content-Type: image/jpeg");
list($width, $height, $type, $attr) = getimagesize($pic);
if($type == "1")
{
$img_in = imagecreatefromgif($pic);
}
if($type == "2")
{
$img_in = imagecreatefromjpeg($pic);
}
if($type == "3")
{
$img_in = imagecreatefrompng($pic);
}
$img_out = imagecreatetruecolor($largeur, $hauteur);
imagecopyresampled($img_out, $img_in, 0, 0, 0, 0, imagesx($img_out), imagesy($img_out), imagesx($img_in), imagesy($img_in));
$t = imagejpeg($img_out);
echo $t;
?>
upload-file.php code :
<?php
$repdossier = $_GET['repdossier'];
$uploaddir = 'upload/'.$repdossier.'/';
$file = $uploaddir . basename($_FILES['uploadfile']['name']);
$dir2 = opendir("upload/$repdossier/");
$getpages=0;
while ($File = readdir($dir2)){
if($File != "." && $File != ".." && $File != "" )
{ $getpages++;
}
}
closedir($dir2);
$calcul = $getpages;
if( @is_file($file) )
{
echo "error2";
}
else
{
if( $calcul >= 5)
{
echo "error1";
}
else
{
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
echo "success";
} else {
echo "error";
}
}
}
?>
Javascript extract from all-index.php (shows the URL generated) :
if(response==="success"){
$('<li></li>').appendTo('#files').html('<img src="miniature.php?pic=upload/<?php echo $repdossier; ?>/'+file+'&w_max=70&h_max=60" height="60" width="70" alt="" /><br />').addClass('success');
}