/    Sign up×
Community /Pin to ProfileBookmark

Automated script for adding pages to database?

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?

    to post a comment
    PHP

    2 Comments(s)

    Copy linkTweet thisAlerts:
    @NightShift58Jan 20.2007 — Something like this:[code=php]<?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;
    ?>[/code]
    Copy linkTweet thisAlerts:
    @Kyleva2204Jan 20.2007 — when you say add the file, do you mean the file name of the file contents?
    ×

    Success!

    Help @blade52x spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.29,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...