Forums »
  PHP Forums And Topics Discussions About Hyper Text Programming Language »
    How To Check If File Exists In A Directory With Php

How To Check If File Exists In A Directory With Php

Description: How To Check If File Exists In A Directory With Php
Tags: how ,to ,check ,if ,file ,exists ,in ,a ,directory ,with ,php
Posted On Fri Feb 29, 2008 By hostman In PHP Forums And Topics Discussions About Hyper Text Programming Language Forums
as a wallpaper website administrator i use php for many of our projects. sometimes its necessary to find out if an image file already exist and to prompt the user to upload a different file because we already have the file in our database. finding out whether a file already exists is easy if you are using php. i dont know much about other languages like asp or cgi, but with php you can use the files_exists() function for checking to see if a file already exits in a website.

so if you want to know how you can check if a file exists with php, you can use the
file_exists() function,


EXAMPLE PHP CODE:
<?php
$filename = '/pathto/file.php';

if (file_exists($filename)) {
echo "The file $filename exists";
} else {
echo "The file $filename does not exist";
}
?>


if you want to give it a try, create a file called checkfile.php and copy and paste the code above and upload to your site. just make sure to change the value of $filename to the file you want to verify and confirm if you already have it in your directories.

hope that helps.

please note, my english is not that good. i speak spanish and im trying to help anyone who can benefit from my knowledge. if you have any comments, please reply to my page here, i would appreciate your comments.

gracias!
theinnovibes.net Wed May 16, 2012
16-5815-the-innovibes-new.png
Its nice you share good information..
Mekey Sun Jan 15, 2012
15-5815-5.jpg
Thanks, it worked for me... keep going.. :)
Sonam Tue May 24, 2011
Thanx.. It really works and nice explained.. Keep posting more ... :)
sunil Sat May 21, 2011
Thanks, works great... was so easy to impliment.

topworlddire
Nick Thu May 12, 2011
This does not work for me. I'm testing to see if my main masthead graphic is found, and it comes back negative. The file IS there, but the program says it's not.

Please help!
Ankur Sat Feb 05, 2011
Thanks, Nice Help
Wilson Sat Jan 29, 2011
Been searching for file_exist coz my script got an error and I found you, thank you.
justin Wed Dec 22, 2010
thanks,its working
Viggo Mon Sep 20, 2010
It's good, yes, but what if you just want to check for ANY file, regardless filename or filetype. Like if a directory exists, but is empty?
Horison Sun Sep 12, 2010
thx for this,
very helpful and easy to understand :)
make more post like this!
Daniel Tue Sep 01, 2009
thanks! i couldn't even tell you weren't a native english speaker until you said so.

stone deft, check out this link: tizag /phpt/fileread.php

once you read the data from a file, you can easily compare it to information you pull from a database. hope that helps!
stone Thu Aug 27, 2009
hey your english isn't bad at all. anyway thanks... is there a way to compare the contents of the file from a database contents?
momo Tue May 19, 2009
works great.. i was stuck. good kharma to you ***
steve Tue Apr 21, 2009
many thanks!!!!
Alex Sat Jan 31, 2009
thanks, i needed that =)
Fredrik Fri Dec 12, 2008
works like a charm! thanks!
waxer989 Tue Aug 21, 2012
Hello and thanks for the tip. Very strait forward! Thanks!
Information
Title: How To Check If File Exists In A Directory With Php
Info: This Post Has Been Viewed 0 Times Since
Date: Fri Feb 29, 2008
Author hostman Received 17 Replies #1111
Related Content
Related Pages
Related Sites
Add Your Website
Share
wallpaperama | Wallpapers | Forums | Terms Of Service

copyright © 2013 wallpaperama - All Rights Reserved - Last Updated Mon Jun 17, 2013 (-8 GMT)
Powered by: Webune Forums V5