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

当我查看文件系统时,文件存在但函数 file_exist 返回 false。

如果我再次运行脚本,它将找到文件。

1
2
3
4
5
6
$result = $client -> getObject ( array (
            ‘Bucket’ => “uploads/$id ,
            ‘Key’ => $file ,
            ‘SaveAs’ => “somepath/$id/$file
        ) ) ;
echo json_encode ( file_exists ( “somepath/$id/$file ) ) ;

这将返回 FALSE,但如果我再次运行脚本并手动插入 url,它将返回 TRUE。

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

thx


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

1 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}”));
  • 错误… :( 我还回显了”somepath/{$id}/{$file}”然后我再次运行脚本硬编码输出,结果是真的!快疯了…


声明:本站(华域联盟www.cnhackhy.com)所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。