2012-09-17 61 views
0

我有一個PHP照相館腳本,它是這樣工作的:htaccess重寫規則以欺騙服務器路徑到腳本?

$image_path  = "../images/11/mycoolphotos/md"; 

如果腳本和照片是在同一臺服務器上,那麼這個完美的作品!

然而,我們剛調到我們所有的圖像到Amazon S3的 - 這樣的路徑是這樣的:

$image_path  = "https://s3.amazonaws.com/mywebsite/images/11/mycoolphotos/md"; 

但它不工作!它不會像../路徑那樣讀取LIST或文件? 我可以包括一個「訂購文件路徑」,它的工作,但我們有8000照片畫廊!太多工作 ?

$order_file_path = "https://s3.amazonaws.com/mywebsite/images/11/mycoolphotos.txt"; 
// this works, but it would take too much time. This just lists the image names, like 1.jpg, 2.jpg,.. so on for that gallery 

我想知道如果我們欺騙服務器在讀(不知道如何爲.htaccess重寫這個)

https://s3.amazonaws.com/mywebsite/images/ 

../ 

如果它的工作?

否則,我不知道該從哪裏出發?

非常感謝!

編輯更新:我發現PATH閱讀功能:任何人都可以解碼這個?我嘗試了下面的建議,但沒有運氣....?

/** 
* Check for image order file. In case it does not 
* exists, read the image directory. 
*/ 
    if (is_file($order_file_path . '/' . $order_file_name)) { 

    $fp = fopen($order_file_path . '/' . $order_file_name, "r"); 
    $row = ''; 
    $use_order_file = 'true'; 

    while ($data = fgetcsv ($fp, 1000, ';')) { 
     $image_data[] = trim($data[0]); 
     $image_file_names[trim($data[0])] = trim($data[0]); 
     $num = count($data); 
     $row++; 

     for ($j = 0; $j < $num; $j++) { 
      $content_data_temp['field_' . $j] = $data[$j]; 
     } 

     $content_data[] = $content_data_temp; 
     $content_data_temp = ''; 
    } 
    fclose ($fp); 
} else if (is_dir($image_path)) { 
    $content_data = ''; 
    $handle = opendir($image_path); 

    while ($file = readdir($handle)) { 
     if (preg_match("/^\.{1,2}$/i", $file)) { 
      continue; 
     } 
     if (preg_match("/\.[a-z]{3}$/i", $file)) { 
      $image_data[] = $file; 
      $image_file_names[$file] = $file; 
     } 
    } 
    closedir($handle); 
} else { 
    echo 'Working on older photos, please check back.'; 
    exit; 
} 

$image_number = count ($image_data); 
+0

而不是硬編碼路徑。將其設置爲一個變量。 '$ baseurl =「http:// amazonaws ...」' –

+0

嗯。你可以做些什麼,我有點失落? – eberswine

+1

不要將路徑硬編碼到路徑字符串中。像我說的那樣將基礎根設置爲一個變量,並像'$ image = $ baseurl一樣引用它。 「/圖片/ ...」'。如果你沒有得到這個,現在停止學習PHP並獲得一本書。然後瞭解SQL注入 –

回答

2

你可以使用mod_rewrite的代理模式爲:

RewriteEngine on 
    RewriteRule ^images/(.*)$ https://s3.amazonaws.com/mywebsite/images/$1 [P] 

乾杯。

+0

很好。所以這將工作? – eberswine

+1

試試看 - 對我來說這個在相關的場景中有效。順便說一句。忘了鏈接到文檔,請參閱:http://httpd.apache.org/docs/2.4/rewrite/proxy.html – pagid

+0

真棒,謝謝! – eberswine