簡體   English   中英

如何在將圖像上傳到數字海洋空間之前檢查文件夾是否存在

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

我從如何使用 php 將圖像上傳到數字海洋空間中得到了這個答案

問題是如何在添加文件之前檢查該文件夾是否存在於數字海洋空間中?

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

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

在空間上創建一個目錄:

$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

您可以使用 php function file_exists檢查文件或目錄的存在

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

另請查看文檔https://www.php.net/manual/en/function.file-exists.php

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM