Click to See Complete Forum and Search --> : Automated script for adding pages to database?


blade52x
01-20-2007, 12:04 AM
Is there some kind of php script that would do the following?

1. Open a directory
2. Check the pages/files inside of the directory (this is the part I'm unsure of how to script)
3. Open up a database - and if a file inside returns 0 zero rows, then add that file to the database.

I could of swore I've seen one on the internet somewhere, but I can't remember where. Something like this would be ideal if all a user had to was create a webpage in a certain directory, and then it would be automatically linked through a database table.

And would something like actually be "slow" if there were 1000 files or so that had to be checked?

NightShift58
01-20-2007, 01:50 AM
Something like this:<?php
$DIRpath = "/path/to/dir/";
$DIRfiles = "*";

$arrFILES = glob($DIRpath . $DIRfiles);

IF ($arrFILES) :
include "db_connect.inc.php";
// mysql_connect(...
// mysql_select_db(...

$sql_chk = "SELECT * FROM `myTable` WHERE `myFIELD` = "
$sql_ins = "INSERT INTO `myTable` SET `myFIELD` = ";

FOREACH ($arrFILES as $key => $thisFILE) :
IF (is_file($thisFILE)) :
$sql1 = $sql_chk . "'" . $thisFILE . "' LIMIT 1";
$qry1 = mysql_query($sq2l) or die("SQL Error: $sql1<br>" . mysql_error());
IF (mysql_num_rows($qry1) == 0) :
$sql2 = $sql_ins . "'" . $thisFILE . "'";
$qry2 = mysql_query($sql2) or die("SQL Error: $sql2<br>" . mysql_error());
ENDIF;
ENDIF;
ENDFOREACH;
ENDIF;
?>

Kyleva2204
01-20-2007, 05:41 PM
when you say add the file, do you mean the file name of the file contents?