2015-11-26 72 views
0

我試圖調用圖片用PHP,源正確調用,但圖像不顯示,只在空白與它的「ALT」的空間。我嘗試在瀏覽器中停用廣告組(這個問題發生在谷歌瀏覽器,Firefox和iOS Safari中,但不在Safari X中),但它沒有任何改變,正如我之前說的,它獲得了正確的路徑和一切當我檢查元素。本身的情況下,名稱爲「OMG/perfiles/ecangis.png」,代碼爲:IMG調用PHP不顯示

if(empty($perfil['fotoperfil']) === false){ 
echo '<img src="', $foto,'" alt="Foto de perfil de ', $perfil['name'],'" style="width:100px; height:100px;">'; 
} 

有誰知道爲什麼圖像不顯示,我怎麼可能使它出現?也不會是最糟糕的知道,如果我停用廣告集團錯了,有什麼辦法來編碼的方式來跳呢?

回答

2

它不是,.來連接到回波/列使用期限

if(empty($perfil['fotoperfil']) === false){ 
echo '<img src="'. $foto.'" alt="Foto de perfil de '. $perfil['name'].'" style="width:100px; height:100px;">'; 
} 
+0

嗯,我改變了這一切,但沒有作出任何differense,只有改變PHP代碼的工作,這始終是如何工作沒有問題, t的位置他像被調用,問題是,瀏覽器不顯示@Ecangis你能告訴我發生什麼屏幕上的圖像本身 – Ecangis

+0

當你運行我的代碼? – Ljubisa

+0

類是善良的,不,其實是不正確的,因爲現在在我做你已經需要註冊看到這樣的,那麼,該頁面是在西班牙的網頁...讓我下班回家,變化然後發佈鏈接。 – Ecangis

3

嘗試使CONCAT有一個觀點:

if(empty($perfil['fotoperfil']) === false){ 
    echo '<img src="'.$foto.'" alt="Foto de perfil de '.$perfil['name'].'" style="width:100px; height:100px;">'; 
} 
+1

響應追加此代碼:)我想我幾秒鐘就打敗你,但我會投你一票。 – Ljubisa

0

因此,該代碼是與實際好嗎「,「 或者 」。」 ,所以我想,這個問題必須在上傳文件或上傳照片並在服務器中創建的文件中的函數的PHP,是這樣的:

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); 
      } 

和功能:

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); 
} 

當圖像被稱爲元素是這個樣子:

<img src="img/perfiles/ecangis.png" alt="Foto de perfil de Enzo" style="width:100px; height:100px;"> 
+0

當你做上傳它會顯示在你的img/perfiles文件夾中嗎? – Ljubisa

+0

是的,以及正確的名稱和一切,這就是爲什麼我不知道它的原因 – Ecangis

+0

有趣的是,該文件的圖像創建文件夾,與他的擴展和一切,但圖像是空白的,我的意思是平面白色 – Ecangis