2014-03-24 39 views
0

我正在使用AWS PHP SDK從S3存儲桶獲取對象。php file_exists在使用AWS PHP SDK時不起作用

當我在文件系統中查看文件存在,但函數file_exist返回false。

如果我再次運行腳本,它會找到該文件。

$result = $client->getObject(array(
      'Bucket' => "uploads/$id", 
      'Key' => $file, 
      'SaveAs' => "somepath/$id/$file" 
     )); 
echo json_encode(file_exists("somepath/$id/$file")); 

此返回FALSE,但如果我再次運行腳本並手動插入它將返回TRUE。

是否可以在腳本仍在運行時無法獲取文件? (也許是時機的問題?)

THX

回答

1

你正在尋找的方法是file_exists,不file_exist

echo json_encode(file_exists("somepath/$id/$file")); 
+0

我用file_exists ....我只是有一個錯字在我qustion –

+0

而somepath/id/file的存在是相對於腳本執行的地方嗎?即如果我的腳本位於/var/www/html/index.php - 並且正在尋找somepath/1/filename,那麼/ var/www/html/somepath/1/filename是您正在驗證的內容嗎? – skrilled

+0

是的,我甚至迴應屏幕上的文件位置,複製它,然後再次運行該腳本與該路徑,然後結果是真的 –