I write this simple code to save an image:
// $randomimage contains a random image url.
$content = file_get_contents($randomimage);
file_put_contents('images/'.$randomimage, $content);
I need a way to NOT rewrite an image with the same name. So, if an image with a certain name already exist in my /images/ folder, then do NOTHING.
It’s simple but I don’t know how to do that.
Sure, use
file_exists.It is important to note that this inherently introduces a race condition into your program, as it is possible that another process could create the file in the time it takes you to check for its existence, then write to the file. In this case, you would overwrite the newly created file. However, it is highly unlikely, but possible.