Reputation: 71
i'm trying to call an image with php, the source is called correctly but the image isn't show, only the space in blank with the "alt" of it. I try with deactivating ad bloc in the browsers (the problem happens in google chrome, firefox and iOS safari, but doesn't in safari OS X) but it didn't any change and as i say before it get the right path and everything when i inspect the element. the name of itself for the case is "omg/perfiles/ecangis.png" and the code is:
if(empty($perfil['fotoperfil']) === false){
echo '<img src="', $foto,'" alt="Foto de perfil de ', $perfil['name'],'" style="width:100px; height:100px;">';
}
Does anybody know why the image isn't show and how could i make it appear?? also wouldn't be the worst to know if i deactivated ad bloc wrong, is there any way to code a way to jump it??
Upvotes: 0
Views: 105
Reputation: 71
So, the code was actually alright with the "," or the "." , so i guess that the problem have to be in the php of the upload file or the function that upload the photo and create the file in the server, being this:
if( empty($_FILES['fotoperfil']['name']) === false){
$tipos = array('jpg','jpeg','gif','png');
$file_name = $_FILES['fotoperfil']['name'];
$file_ext = strtolower(end(explode('.', $file_name)));
$file_temp = $_FILES['fotoperfil']['tmp_name'];
$size = getimagesize($file_temp);
if($size[0] !== $size[1]){
$errors[]="Las fotos deben mantener la proporcion cuadrada establecido, por favor edita la foto en tu computador antes de subirla.";
} else if($size[0] > 400 or $size[1] > 400){
$errors[]="Las fotos pueden tener un tamaño maximo de 400 pixeles, puedes disminuir su tamaño en el computador y tratar de subirla denuevo";
}
if (in_array($file_ext, $tipos) === true){
if(empty($user_data['fotoperfil']) === false){
borrarfoto($user_data['userid'], $user_data['fotoperfil']);
}
cambiarfoto($user_data['idname'], $user_data['userid'], $file_temp, $file_ext);
}
and the function:
function cambiarfoto($name, $userid, $file, $ext){
$name = sanitize($name);
$file = sanitize($file);
$ext = sanitize($ext);
$file_path = 'img/perfiles/' . $name . '.' . $ext;
move_uploaded_file($file, $file_path);
mysql_query("UPDATE `usuarios` SET `fotoperfil` = '" . mysql_real_escape_string($file_path) . "' WHERE `userid` = " . (int)$userid);
}
when the image is called the element is shown like this:
<img src="img/perfiles/ecangis.png" alt="Foto de perfil de Enzo" style="width:100px; height:100px;">
Upvotes: 0
Reputation: 1068
Try making the concat with a point :
if(empty($perfil['fotoperfil']) === false){
echo '<img src="'.$foto.'" alt="Foto de perfil de '.$perfil['name'].'" style="width:100px; height:100px;">';
}
Upvotes: 3
Reputation: 1085
Its not ,
its .
to concatenate on to the echo / string use period
if(empty($perfil['fotoperfil']) === false){
echo '<img src="'. $foto.'" alt="Foto de perfil de '. $perfil['name'].'" style="width:100px; height:100px;">';
}
Upvotes: 2