Friday, 27 November 2015

36_Checking_File_exists_in_PHP

Checking File is exists in PHP


In PHP the image uploads / store operation if we want to check that specific files are exists or not, at that time we are going to perform the operation as specify below.



This will generate the random file name, while in the above code md5() function create 32 character hash from “image1.jpeg”.


The file name which is generated randomly will store on the server. But there is one problem during the live server, imagine that other user has upload the same image1.jpeg file and also the random number “194” and last random number “178” is same for both the user. So at that time we need to use file_exists () function of PHP.



So here in the above example is file does exists then do nothing else create file.


Very useful for storing the images in to the folder with random number. Now run the page file_exists.php page. It shows me nothing/ blank page. Go back from browser and check harshida.txt file is generated or not.


No comments:

Post a Comment