【问题标题】:php file_exists doesnt work when working with AWS PHP SDK使用 AWS PHP SDK 时 php file_exists 不起作用
【发布时间】:2014-03-25 06:12:56
【问题描述】:

我正在使用 AWS PHP SDK 从 S3 存储桶中获取对象。

当我查看文件系统时,文件存在但函数 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,但如果我再次运行脚本并手动插入 url,它将返回 TRUE。

是不是在脚本仍在运行时我无法获取文件? (可能是时间问题?)

谢谢

【问题讨论】:

    标签: php file file-upload amazon-web-services amazon-s3


    【解决方案1】:

    您要查找的方法是 file_exists,而不是 file_exist

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

    【讨论】:

    • 并且 somepath/id/file 的存在与脚本执行的位置有关吗? IE。如果我的脚本位于 /var/www/html/index.php - 我正在寻找 somepath/1/filename 那么 /var/www/html/somepath/1/filename 是你正在验证的存在吗?
    • 是的,我什至回显以筛选文件位置,复制它,然后使用该路径再次运行脚本,然后结果为真
    • 只是为了笑,为我做这个:echo json_encode(file_exists("somepath/{$id}/{$file}"));
    • false... :( 我还回显了“somepath/{$id}/{$file}”,然后我再次运行脚本硬编码输出,结果是真的!快疯了。 ..
    猜你喜欢
    • 2017-05-14
    • 2017-03-11
    • 2011-11-05
    • 2010-11-20
    • 2012-07-08
    • 1970-01-01
    • 2017-02-21
    • 2013-04-15
    • 2016-12-21
    相关资源
    最近更新 更多