关于文件:使用 AWS PHP SDK 时,php file_exists 不起作用 | 珊瑚贝

php file_exists doesnt work when working with AWS PHP SDK


我正在使用 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}”然后我再次运行脚本硬编码输出,结果是真的!快疯了…


来源:https://www.codenong.com/22621654/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9002.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?