本文介绍如何判断文件是否存在。
以下代码用于判断指定的文件是否存在:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | <?php if (is_file(__DIR__ . '/../autoload.php' )) { require_once __DIR__ . '/../autoload.php' ; } if (is_file(__DIR__ . '/../vendor/autoload.php' )) { require_once __DIR__ . '/../vendor/autoload.php' ; } use OSS\OssClient; use OSS\Core\OssException; // 阿里云主账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维,请登录 https://console.cloud.tmall.com 创建RAM账号。 $accessKeyId = "<yourAccessKeyId>" ; $accessKeySecret = "<yourAccessKeySecret>" ; // Endpoint以杭州为例,其它Region请按实际情况填写。 $bucket= "<yourBucketName>" ; $object = "<yourObjectName>" ; try { $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint); $exist = $ossClient->doesObjectExist($bucket, $object); } catch (OssException $e) { printf(__FUNCTION__ . ": FAILED\n" ); printf($e->getMessage() . "\n" ); return ; } print(__FUNCTION__ . ": OK" . "\n" ); var_dump($exist); |