I'm trying to make a basic news system in PHP and I'm about to finish but I have a little problem in the image upload part. The problem is when I try to resize the image when it exceeds a certain size. The image uploads correctly but in a null state: the image is in black. When I upload the image in the form of my html it displays me the following warning:
Warning: imagecopyresampled() expects parameter 2 to be resource, string given in C:\USBWebserver v8.6oot\CCCHermosillo\anadir_noticia.php on line 116
here is the part for the image upload:
if($_POST['añadir']) {
if (is_uploaded_file($_FILES['image']['tmp_name'])) {
if($_FILES['image']['size'] < 500000) {
copy($_FILES['image']['tmp_name'], "C:/USBWebserver v8.6/root/CCCHermosillo/image_upload/".$_FILES['image']['name']);
$subio = true;
}else{
// $ruta_imagen = $_FILES['image']['name'];
$ruta_imagen = $_FILES['image']['tmp_name'];
$miniatura_ancho_maximo = 200;
$miniatura_alto_maximo = 200;
$info_imagen = getimagesize($ruta_imagen);
$imagen_ancho = $info_imagen[0];
$imagen_alto = $info_imagen[1];
$imagen_tipo = $info_imagen['mime'];
$lienzo = imagecreatetruecolor( $miniatura_ancho_maximo, $miniatura_alto_maximo );
switch ( $imagen_tipo ){
case IMAGETYPE_JPEG:
$imagen = imagecreatefromjpeg( $ruta_imagen );
break;
case IMAGETYPE_PNG:
$imagen = imagecreatefrompng( $ruta_imagen );
break;
case IMAGETYPE_GIF:
$imagen = imagecreatefromgif( $ruta_imagen );
break;
}
imagecopyresampled($lienzo, $imagen, 0, 0, 0, 0, $miniatura_ancho_maximo, $miniatura_alto_maximo, $imagen_ancho, $imagen_alto);
imagejpeg( $lienzo, ("C:/USBWebserver v8.6/root/CCCHermosillo/image_upload/".$_FILES['image']['name']), 90 );
$subio=TRUE;
}
}
if($subio) {
echo "<br>El archivo subio con exito";
} else {
echo "<br>El archivo no cumple con las reglas establecidas";
}
die();
}
the warning is given in this line:
imagecopyresampled($lienzo, $imagen, 0, 0, 0, 0,$miniatura_ancho_maximo,$miniatura_alto_maximo, $imagen_ancho, $imagen_alto);