4

How do I know if a folder exists before creating it in laravel?

 3 years ago
source link: https://www.codesd.com/item/how-do-i-know-if-a-folder-exists-before-creating-it-in-laravel.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How do I know if a folder exists before creating it in laravel?

advertisements

I need to know if a folder exists before creating it, this is because I store pictures inside and I fear that the pictures are deleted if overwrite the folder. The code I have to create a folder is as follows

$path = public_path().'/images';
File::makeDirectory($path, $mode = 0777, true, true);

how can I do it?


See: file_exists()

Usage:

if (!file_exists($path)) {
    // path does not exist
}

In Laravel:

if(!File::exists($path)) {
    // path does not exist
}

Related Articles

How do I know if a folder exists and how to create a folder?

I'm trying to create a folder if it doesn't exist. I'm using Windows and I am not interested on my code working in other platforms. Never mind, I found the solution. I was just having a inclusion problem. The answer is: #include <io.h> // For access

How do I know if a file exists in C?

How would I know if a file exists in my current directory in C? I'm prompting the user and I'm trying to see if the file they type in already exists or not. Here's what I got: int a=0; char ing[100]; FILE * inp; while (a=0); { printf("Input file name

How do I check if a file exists before importing or importing it into JSP?

Assuming that requestScope.importMe is expecting a path to a JSP file <c:choose> <c:when test="${!empty requestScope.importMe && fileExists(requestScope.importMe) }"> <c:import url="${requestScope.importMe}" />

How to check the directory exists before creating a new directory in JSCH

How to check the existence of the directory before creating a new directory using JSCH SFTP API? I am trying to use lstat but not sure it's doing the job that I need.Thanks in advanceIn situations like this it is always better to just do the create a

Check if a temporary table exists and delete it if it exists before creating a temporary table

I am using the following code to check if the temporary table exists and drop the table if it exists before creating again. It works fine as long as I don't change the columns. If I add a column later, it will give an error saying "invalid column&quo

Check if the database exists before creating

This seems pretty trivial, but it is now frustrating me. I am using C# with SQL Server 2005 Express. I am using the following code. I want to check if a database exists before creating it. However, the integer returned is -1 and this is how MSDN defi

How to know if a Streetview exists before launching Streetview intent

Launching a Streetview intent for a location doesn't guarantee that a Streetview exists for that location. If the Streetview doesn't exist, the user just sees a black screen that spins. Is there a way to programmatically check if it exists before lau

How do I know if a row exists in a table?

For example: select name from person where id=2; I wand to know if this row exists, and depending on its existence perform a certain task. I wan to do this using jdbc.Use PreparedStatement to invoke this select query, After the successful execution o

How do I know if a directory exists on Delphi XE2 * correctly *?

I simply need to check if a directory exists! But if the directory is "E:\Test" where E: is CD/DVD drive and there is no disk inserted on it, I see the following Delphi and Windows issues. The first method: function DirExists(Name: string): Bool

How do I check if a java.util.logging.Logger already exists before creating it?

I am running into a java.util.logging deadlock that I suspect is related to the way that I am checking for the existence of a Logger before (possibly) creating it. My question is: What is the best way to check-in a threadsafe manner-for a Logger's ex

How do I know which user I used to create a svn repository?

How can I know which user I used to co an svn repository? Is there an svn command for this? update: so, how can I ci as some users?SVN working copies aren't checked out as a certain user (though on some systems the files will be owned by a certain us

How can Apple know if an application has been created in MonoTouch?

Monotouch compiles the app into the native code. How can Apple know that the app was built using MonoTouch? Does Monotouch leaves a signature in the application? Does Monotouch has its own libraries which could be a trace of the origin or it compiles

Insert a file into the Drive folder (check if the folder exists, otherwise create a folder)

Im trying to insert a specific file in Google Drive to a folder. I also want to check if there is a folder with name 'testFolder' if Yes, then insert file to that already existing folder, else create one named 'testFolder'. Here is what i have come u

How to check if the COM port exists before opening the connection in Visual C #

I need to check if selected COM port exist before conecting to it (It gives error) I'm using Visual Studio Express 2013 C#. Or, is there some way to hide that error? Thanks.. ~RichardI'd use System.IO.Ports.SerialPort.GetPortNames - it returns an arr

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK