homepage Welcome to WebmasterWorld Guest from 54.145.182.50
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
data entry and comparison
perl, database, php
crackpipe

5+ Year Member



 
Msg#: 3983804 posted 3:02 am on Sep 4, 2009 (gmt 0)

I'm an enthusiast working on a home-built CMS for a few thousand files. I've cobbled together a relatively nice PHP form which allows me to enter a file's name, its description, a few tags(in progress), the number of pages in the file, and then submits/inserts the record into the database. I want to automate data-entry as much as possible. I know a bit of bash, but am new to PERL.

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">
<html>
<head>
<title>enter files</title>
<base target="_top">
<link href="table03.css" rel="stylesheet" type="text/css" media="screen" />
<style type="text/css"></style>
</head>
<body text="#000000" link="blue" vlink="red" bgcolor="lightgray">
<div id="banner">enter file descriptions and tags
</div>
<p> Welcome, Internet user.<br>
IP address: <b><? echo $_SERVER['REMOTE_ADDR']?></b> ::
Browser string: <? echo $_SERVER['HTTP_USER_AGENT']?> .</p>


<!-- TABLE W/FORMS -->
<div id="contentwrapper">
<div id="contentcolumn">
<form action="<?php
$hostname="foo";
$username="foo";
$password="foo";

//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");

$descrip=$_POST['item_desc'];
$filename=$_POST['item_name'];
$pages=$_POST['item_pages'];

mysql_query("INSERT INTO Items (item_name, item_desc, item_pages) VALUES ('$filename','$descrip' '$pages')") or die(mysql_error());

//DB CLOSING
mysql_close($dbhandle);
?>" method="post" >

<table bordercolorlight="#CFCFCF" bordercolordark="#FFFFFF" border="1"
bordercolor="#cfcfcf" cellpadding="2" cellspacing="0" width="100%">
<tbody>
<tr>
<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>
</tr>
<tr>
<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>
</tr>
<tr>
<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>
</tr>
</tbody></table>
<p>&nbsp;</p>
<p>
<input type="submit" name="Submit" id="Submit" value="get untagged" /> &nbsp; &nbsp;
<input type="submit" name="Submit" id="Submit" value="submit" /> &nbsp; &nbsp;
<input type="reset" name="Submit" id="Submit" value="reset" />
</p>
</form>
</div></div>
<br>
</tbody></table></div></div>

<!-- DB CLOSE (PHP) -->
<?php mysql_close($dbhandle); ?>
<!-- CLOSE (HTML) -->
</body></html>

 

janharders

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3983804 posted 9:32 am on Sep 4, 2009 (gmt 0)

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.

crackpipe

5+ Year Member



 
Msg#: 3983804 posted 6:39 pm on Sep 4, 2009 (gmt 0)


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.

Thanks. Looking into this. Appears I'll need to find some commands, PHP or PERL, to compare an array of files from the directory with an array of files from MySQL to determine what's already been entered into the DB. I'll post back here when I get further down the road. I appreciate the info.

janharders

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3983804 posted 7:31 pm on Sep 4, 2009 (gmt 0)

there aren't really any special commands that will solve that in one step, instead you'd

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved