| | |
Files linked to MySQL records
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Hey, just need a little help on this one. I have a script allows a user to choose from a list of files in a directory for a form. When they submit the form, it adds the files name and url to a couple fields in the database for that entry.
What I need to do is every now and then, I need to see if any of the files in that directory are currently in use in any records in the database. In other words, I need to compare each of the file names with the column "file_name" in my database, and test to see if there are any matches. This way I will be able to clean out any old, unused files.
If the query returns no results for any one of the files, I'll know I can delete that file.
Any ideas?
What I need to do is every now and then, I need to see if any of the files in that directory are currently in use in any records in the database. In other words, I need to compare each of the file names with the column "file_name" in my database, and test to see if there are any matches. This way I will be able to clean out any old, unused files.
If the query returns no results for any one of the files, I'll know I can delete that file.
Any ideas?
•
•
Join Date: Aug 2006
Posts: 138
Reputation:
Solved Threads: 2
[php]
chdir("path/to/directory");
$files=glob("*");
foreach ($files as $file){
$result=mysql_query("select * from files where file_name='".mysql_real_escape_string($file)."'");
if(mysql_num_rows($result)==0){
echo "$file is not in use";
}
}
[/php]
chdir("path/to/directory");
$files=glob("*");
foreach ($files as $file){
$result=mysql_query("select * from files where file_name='".mysql_real_escape_string($file)."'");
if(mysql_num_rows($result)==0){
echo "$file is not in use";
}
}
[/php]
Last edited by php_daemon; Feb 7th, 2007 at 2:54 pm.
![]() |
Similar Threads
- Passing txt files into a programand writeln info out (Pascal and Delphi)
- Modem keeps dialling when i open files (Viruses, Spyware and other Nasties)
- uploading .txt file via phpmyadmin to Mysql (MySQL)
- Can't see MySql records using PHP with any browser (MySQL)
- Can't see mysql records using php in any browser (PHP)
Other Threads in the PHP Forum
- Previous Thread: Choosing File Upload Destination from dropdown
- Next Thread: How to keep track of no. of visitors
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube





