Welcome to WebmasterWorld Guest from 18.104.22.168
The tags and descriptions for each file must be hand entered, but I want to automate the part of entering the thousands of filenames from that folder into individual records in the database:
1) Assuming I have 1,500 files in that folder, I want the PERL script to insert 1,500 records into the database. The script would apparently need to run the equivalent of a diff against the filename column in the database and an ls of the filenames in the folder so that only files not already in the database would be added.
2) A second mission of the script is to determine if, in each record, file descriptions have been added to that record and, if not, to feed the names of files without tags or descriptions to my PHP data-entry form automatically for adding that information to the record. For this, a second diff-like operation would apparently seek records with null values in the description field. Files without a description or tag would then be routed to the PHP form for adding a description and tag to the record.
If such a script were available, over a series of weekends I would eventually enter metadata for all of the files in the folder. I would know I had completed the process when filenames stopped coming into my form to add metadata.
I hope this all makes sense. If so, has anyone seen or accomplished anything like this? Thanks.
Incidentally, I believe this requires PERL, not simply PHP, which is the reason for posting in this forum, but here is my PHP data entry form, which works well, but to which I want to add a script to automatically add the value for the "item_name" form field in line 81.
<?php session_start(); ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<link href="table03.css" rel="stylesheet" type="text/css" media="screen" />
<body text="#000000" link="blue" vlink="red" bgcolor="lightgray">
<div id="banner">enter file descriptions and tags
<p> Welcome, Internet user.<br>
IP address: <b><? echo $_SERVER['REMOTE_ADDR']?></b> ::
Browser string: <? echo $_SERVER['HTTP_USER_AGENT']?> .</p>
<!-- TABLE W/FORMS -->
//connection to the tablespace
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
//connection to a database
$selected = mysql_select_db("foo",$dbhandle)
or die("Could not select database");
mysql_query("INSERT INTO Items (item_name, item_desc, item_pages) VALUES ('$filename','$descrip' '$pages')") or die(mysql_error());
?>" method="post" >
<table bordercolorlight="#CFCFCF" bordercolordark="#FFFFFF" border="1"
bordercolor="#cfcfcf" cellpadding="2" cellspacing="0" width="100%">
<td align="left" bgcolor="#009dd0" valign="top"><b><font color="#ffffff">description</font></b></td>
<td bgcolor="#009dd0"><b><font color="#ffffff">tags</font></b></td>
<td align="center" bgcolor="#009dd0"><b><font color="#ffffff">pages</font></b></td>
<td bgcolor="#009dd0"><b><font color="#ffffff">filename</font></b></td>
<td><TEXTAREA class="expands" name="item_desc" rows="8" cols="35"></TEXTAREA></td>
<td <input name="#" type="text" size="35" />
<td <input name="item_pages" type="text" size="5" />
<td> <input name="item_name" type="text"></input></td>
<td bgcolor="#bdd2d1" width="35%"><?php echo "$_POST[item_desc]"; ?></td>
<td bgcolor="#bdd2d1" width="35%"><b>tags</b></td>
<td bgcolor="#bdd2d1" width="5%"><?php echo "$_POST[item_pages]"; ?></td>
<td bgcolor="#bdd2d1"><p class="mono" size="100%"><?php echo "$_POST[item_name]"; ?></p></td>
<input type="submit" name="Submit" id="Submit" value="get untagged" />
<input type="submit" name="Submit" id="Submit" value="submit" />
<input type="reset" name="Submit" id="Submit" value="reset" />
<!-- DB CLOSE (PHP) -->
<?php mysql_close($dbhandle); ?>
<!-- CLOSE (HTML) -->
it's absolutely possible, but you don't need perl for that.
what you need is:
opendir to open a directory
readdir to read entries
closedir to close the directory
and the sql to check wether the file is in the db already.
you can easily do that with php, if you're more familiar with it. Of course, if you want to get into perl, you can do that as a start, and I'm always pro perl ... but you don't have to.
read a filename from the directory (readdir)
check wether it is in the db
enter it, if not
take a look at the php documentation for opendir [php.net] for information and examples. that combined with some sql statements should get you were you want to go.