简体   繁体   中英

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

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

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

please also check documentation https://www.php.net/manual/en/function.file-exists.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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