简体   繁体   English

如何在将图像上传到数字海洋空间之前检查文件夹是否存在

[英]how to check if folder exists before upload images to digital ocean space

I took this answer from how to upload images to digital ocean space using php我从如何使用 php 将图像上传到数字海洋空间中得到了这个答案

The question is how to check if the folder exist on digital ocean space before adding a file please?问题是如何在添加文件之前检查该文件夹是否存在于数字海洋空间中?

$source = "SOME_FOLDER/image.JPG";
$filename_on_space = "image.JPG";

$space->UploadFile($source, "public","path/to/directory/" . $filename_on_space, "image/jpeg");

create a directory on space:在空间上创建一个目录:

$path_to_file = "FOLDER_name/"; //dont miss the last slash
$space->UploadFile($path_to_file, "public","sub/folders/" . 
$path_to_file, 'text/directory'); // be noted for the mime type for the folder

you can check existance of file or directory using php function file_exists您可以使用 php function file_exists检查文件或目录的存在

if(file_exists($path_to_file)){
 // do your logic
}

please also check documentation https://www.php.net/manual/en/function.file-exists.php另请查看文档https://www.php.net/manual/en/function.file-exists.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM