2013-09-04 2 views
0

file_exists이 작동하지 않습니다! 그러나 URL (코드에서 $ img)이 브라우저에 주어지면 이미지가 표시됩니다. 나는file_exists()가 작동하지 않지만 이미지 URL이 브라우저에 표시되면 이미지가 표시됩니다.

include_once("../inc/inc_constants.php"); 

include_once("database/db.php"); 

include_once("includes/global.php"); 

ini_set('max_execution_time',300); 

     $sql="select plan_image_name from mp_new_project_images 
        where project_code in 
        (select project_code from mp_new_project 
        where project_status='Active') "; 

      $sql_result=mysql_query($sql) or die(mysql_error()); 



     while($sqlrow=mysql_fetch_array($sql_result)) 
     { 
      //HOME is "http://ip address/" 

    $img = HOME."images/properties/thumbs_400/".$sqlrow['plan_image_name']." "; 

    if(file_exists($img)) 
    { 

    $dest =HOME."images/properties/thumbs_400/compress_50/".$sqlrow['plan_image_name']." "; 
    $dest1=HOME."images/properties/thumbs_400/compress_20/".$sqlrow['plan_image_name']." "; 
    $dest2=HOME."images/properties/thumbs_400/compress_10/".$sqlrow['plan_image_name']." "; 

    $size = getimagesize($img); 

    switch($size['mime']) { 
     case 'image/jpeg': 
      $im=imagecreatefromjpeg($img); 
      imagejpeg($im,$dest,50); 
      imagejpeg($im,$dest1,20); 
      imagejpeg($im,$dest2,10); 
     break; 
     case 'image/png': 
      $im = imagecreatefrompng($img); 
      imagepng($im,$dest,50); 
      imagepng($im,$dest1,20); 
      imagepng($im,$dest2,10); 
     break; 
     case 'image/gif': 
      $im = imagecreatefromgif($img); 
      imagegif($im,$dest,50); 
      imagegif($im,$dest1,20); 
      imagegif($im,$dest2,10); 
     break; 
     default: 
      return false; 
     break; 
     } 
    } 

} 
+0

'홈'값은 무엇입니까? – MisterBla

+0

HOME은 http : // ip address/ – phplearner

+1

입니다. HOME이 url이면 작동하지 않습니다 .... file_exists()는 서버 파일 시스템 –

답변

0

파일 이름이 아닌 IP 주소 file_exisits 기능을 대신 가정에서 사용하는 실제 경로에

'HOME' constant should be /var/www/html not ('http://url') for example 

$img = HOME."images/properties/thumbs_400/".$sqlrow['plan_image_name']." "; 

if(file_exists($img)) { 

} 
0

Path to the file or directory해야 ... file_exists()은 하드 드라이브 경로를 사용하지만, 내가 도와 줘요, 이해할 수 알고있다. 실제 경로 제대로을 얻을이 "의/var/www가/public_html을 /"

사용은 phpinfo() 함수를 알 수있는 실제 경로

또는

사용

dirname(__FILE__) . DIRECTORY_SEPARATOR 

같은 것입니다 물리적 경로를 동적으로.

0

이 코드 당신은 :

//HOME is "http://ip address/" 

$img = HOME."images/properties/thumbs_400/".$sqlrow['plan_image_name']." "; 

if(file_exists($img)) 
{ 

가 작동하지 않습니다. file_exists() 함수는 로컬 디렉토리 경로를 기다리고 있습니다. 원격 경로에 대해 fopen()을 사용할 수 있습니다.

$handle = fopen("http://www.example.com/", "r"); 

if (!$handle) 
    { 
    //no file 
    } 
else 
    { 
    // file exists 
    } 

http://php.net/manual/en/function.fopen.php

나는 그것이 IP 주소와 함께 작동 생각하지만, IP 주소가 자주 공유로주의하십시오.

+0

ur fopen 메서드를 사용하여 작동하지만 파일이 대상 폴더에서 압축되지 않습니다. 코드에 오류가 없습니다. 나는 경로 ($ dest, $ dest1, $ dest2)에 문제가 있다고 생각한다. – phplearner

+0

압축되지 않은 파일의 문제에 대해 설명하고 확장 할 수 있습니까? 당신이 기대하는 것은 무엇입니까? – James

관련 문제