Maybe it's an there are a lot of topics aout this argument, but I've read all of them and I can't find the solution(maybe it's very stupid and I can't see it). I'm trying to modificy(if neccessary) and move the file I've uploaded to a certain dir. The problemi is that I cannot getimagesize info
Here the form
echo' <form enctype="multipart/form-data" action="',$_SERVER['REQUEST_URI'],'" method="post">
<input type="hidden" name="file" value="file_upload" />
<input type="file" multiple="multiple" name="upload_immagini" /><br />
<input type="hidden" value="',$id,'" name="id_prodotto" />
<input type="submit" value="Carica" />
</form>';
$id it's from another page and it works fine. I need to create the directory where I want to move the files after the resize
//UPLOAD
if(isset($_POST['file']) and $_POST['file']=='file_upload'){
//Set $id
$id=(int)$_POST['id_prodotto'];
$dir='../media/images/prodotti/'.$id;
//Check if something was uploaded
if(!empty($_FILES['upload_immagini'])){
$d=count($_FILES['upload_immagini']['name']);
foreach((array)$_FILES['upload_immagini']['name'] as $i => $nome)
{
//Check the extension
$estensione=explode(".", $_FILES['upload_immagini']['name'][$i]);
if(!$estensione == 'png' || !$estensione == 'jpg' || !$estensione=='jpeg'){
echo 'Il file ',$_FILES['upload_immagini']['name'][$i],' non è un\'immagine';
}//If it's an image, I resize it
else{
//Info from the original one
list($width, $height, $type, $attr) = getimagesize($_FILES['upload_immagini']['tmp_name'][$i]);
//Start Resize
if($width > $height and $width > 900){
$img_width=900;//max wisth
$img_height=round(($height/$width)*$img_width);
}elseif($height > $width and $height > 900){
$img_height=900;//max height
$img_width=round(($height/$width)*$img_height);
}
$img_ridimensionata=imagecreatetruecolor($img_width,$img_height);
if($estensione=='png'){
$source=imagecreatefrompng($_FILES['upload_immagini']['name'][$i]);
}else{
$source=imagecreatefromjpeg($_FILES['upload_immagini']['name'][$i]);
}
//Check the directory existence
if (is_dir($dir)) {
echo 'Cartella già esistente';
} else {
mkdir($dir, 0777);
imagecopyresized($img_ridimensionata, $source, 0, 0, 0, 0,$img_width, $img_height, $width, $height);
imagepng($img_ridimensionata,$dir, 8);
imagedestroy($_FILES['upload_immagini']['name'][$i]);
}
}
}
}
I'm getting those errors:
"Warning: imagecreatetruecolor(): Invalid image dimensions in /home/sakeh0/public_html/sportlife/admin/c/prodotti.php on line 128
Warning: imagecreatefromjpeg(0): failed to open stream: No such file or directory in /home/sakeh0/public_html/sportlife/admin/c/prodotti.php on line 132".
I think because in getimagesize()
there's no value.