2013-10-31 193 views
-1

我在我的電腦上有這段代碼,它運行得非常好,但是當其他人試圖在不同的環境中運行它時,getimagesize()由於某種原因每次都返回false(應該返回true)。任何想法爲什麼這段代碼將在不同的環境中完全不同?爲什麼getimagesize()返回false?

$i = 2; 
while ($i != 0){ 
    $theFile = "url/to/images/" . $image . $i . ".GIF"; 
    //echo $theFile . "<br />"; 
    if ($imageSize = @getimagesize($theFile)){ 
     //echo "added...<br />"; 
     $theRow .= "<a href='" . $theFile . "' rel='lightbox[" . $image . "]'></a>"; 
     $i++; 
    }else{ 
     $i = 0; 
    } 
} 

如果我取消了兩行那裏所有$theFile的打印的畫面精美,而且都是有效的網址,但它只是一堆

thisimage2.GIF 
thatimage2.GIF 
anotherimage2.GIF 
... 

他們都最終與2.GIF但有很多應該有3,4,5,6到12.FIF,但它永遠不會增加$ i,因爲它從不返回真正的getimagesize()。同樣,當我取消註釋echo $theFile . "<br />";時,它會將有效的URL打印到圖像上,以便其他人可以將其粘貼到瀏覽器地址欄中,然後查看圖像。

我正在運行php 5.4.17,完全相同的代碼對我來說工作正常。另一臺機器正在運行php 5.4.7,並且無法正常工作。我試圖查找getimagesize()的兩個版本之間的差異,但找不到任何東西。

編輯:當沒有它不工作它提供了以下警告在機器上和getimagesize「@」()運行:Warning: getimagesize(): Unable to find the wrapper 「https」 - did you forget to enable it when you configured PHP?

+6

開始通過擺脫@的''和讀取可能錯誤消息? – deceze

+0

你要更改$ image和$ theFile? – Fredd

+0

我會這麼做,讓這個人再次運行它。 –

回答

0

有幾件事情錯在這裏。幸運的是,他們中的大多數都很容易修復。

  1. $image似乎沒有被定義在任何地方,但也許它已經和你只是沒有包括它。
  2. 在每個開始和結束<a>標籤之間沒有文字,所以你會看到的唯一鏈接是這樣的鏈接:<a href='url/to/images/imagename1.GIF' rel='lightbox[]'></a>(但是,也許這是故意的)。
  3. $theRow似乎沒有迴應任何地方,但也許它是,你只是沒有包括該部分。此外,它看起來不像$theRow最初是在任何地方定義。
  4. 您的while()循環將只顯示最後處理的圖像。在這種情況下,我會使用for()循環。

如果你的目標是建立$theRow,然後在結束時顯示了這一切,我會像這樣的東西,而不是去:

<?php 
// EDIT: check to see if openssl exists first, due to the https error you're receiving. 
$extensions = get_loaded_extensions(); 
if (!in_array('openssl', $extensions)) { 
    echo 'OpenSSL extension not loaded in this environment'; 
} 
// Define $theRow first 
$theRow = ''; 
// "Given that $i = 0, while $i is less than 3, auto-increment $i" 
for ($i = 0; $i < 3; $i++){ 
    $theFile = "url/to/images/" . $image . $i . ".GIF"; 
    //echo $theFile . "<br />"; 
    // Remove the @ sign to display errors if you want 
    if ($imageSize = @getimagesize($theFile)){ 
    //echo "added...<br />"; 
    // Add to $theRow, using $theFile as the text displayed in between each <a> tag 
    $theRow .= "<a href='" . $theFile . "' rel='lightbox[" . $image . "]'>" . $theFile . "</a>"; 
    } 
    else { 
    //This should only appear if $imageSize didn't work. 
    echo '$imageSize has not been set for ' . $theFile . '<br />'; 
    } 
} 
// Now that $theRow has been built, echo the whole thing 
echo $theRow;