Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP
Author Message
blith
Client



Joined: Jul 18, 2003
Posts: 977

PostPosted: Thu Aug 21, 2008 11:10 am Reply with quote

Okay, my old site had some 1166 download files. I have them on disc and I am going to upload them to my files directory where I store my current downloads. What I would like to do is write some php that would echo a INSERT statement that I could then cut and paste into myphp admin. A great friend of mine came up with this so far:
Code:


<?php
if ($handle = opendir("yourdirhere")) {
  echo "<p>";
 while (($file = readdir($handle)) !== false) {
   if (filetype($dir . $file) == "file") {
     $query = "INSERT INTO mydatabase VALUES ('','$file');";
     echo "$query<br />";
    }
  }   
 closedir($handle);
 echo "</p>";
}
?>

What I need to figure out is A) how to write the $query so that the structure is the same as downloads_downloads, and B) how can I put this in the folder where the files reside and then call it? I have tried but I get access denied.

Can anyone help or perhaps give me some direction and instruction? Thank you Smile
 
View user's profile Send private message Visit poster's website
Gremmie
Former Moderator in Good Standing



Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Thu Aug 21, 2008 11:58 am Reply with quote

Do you have access to phpMyAdmin? You can easily look at the structure of that table with it. Or examine the downloads module admin code to see some examples of how to insert into it.

_________________
GCalendar - An Event Calendar for PHP-Nuke
Member_Map - A Google Maps Nuke Module 
View user's profile Send private message
blith







PostPosted: Thu Aug 21, 2008 12:24 pm Reply with quote

I will look at the structure of the database and try to write that into the $query. Can you advise as to how I can call this code? I call it readdir.php and when I use that I get a 503 error or access denied? Thank you
 
Gremmie







PostPosted: Thu Aug 21, 2008 12:55 pm Reply with quote

503 usually means there is a server configuration problem. Its hard to say without knowing anything about your site or the server configuration. Is there an .htaccess file in that directory that is preventing the running of the script?

A couple of points to think about:

You don't have to call it from the directory where the files are, just adjust the path in your script.

If it is easier for you, you don't have to write this in PHP, or even run it on your server. Why not use Perl, Python, Basic, C, C++, etc on your PC? All you are going to get out of this is SQL statements that you are going to cut & paste into phpMyAdmin, right?
 
blith







PostPosted: Thu Aug 21, 2008 1:27 pm Reply with quote

There is a .htaccess in there

yes, that is right, all I am going to get are sql statements. I do not know anything about the other languages you suggested. How would I do this? If you do not mind helping more... Wink
 
fkelly
Former Moderator in Good Standing



Joined: Aug 30, 2005
Posts: 3312
Location: near Albany NY

PostPosted: Thu Aug 21, 2008 2:36 pm Reply with quote

I dunno. How about something like doing it in Excel. Copy into column B the names of your files. Then copy 'insert into mydatabase Values ('",'' into column A. Then put the closing );"; into column C.

Then block columns A B and C and copy and paste them into PHPmyadmin. I'm not sure I got every last ' correct but something like that might work without any programming.
 
View user's profile Send private message Visit poster's website
blith







PostPosted: Fri Aug 22, 2008 3:38 pm Reply with quote

This is a useful little bit of php.

I used it to read the dir of a folder full of .zip files to make insert statements for my sql. This way I could ftp all my files, run this, and then do an insert and all my files would have download entires. Of course I have to go back and fill in some of the blanks but it is better than doing them by hand...

Code:


<?php
if ($handle = opendir("/your location here")) {
  echo "<p>";
 while (($file = readdir($handle)) !== false) {
   //if (filetype($file) == "file") {
     $query = "INSERT INTO `nuke_nsngd_downloads` (`lid`, `cid`, `sid`, `title`, `url`, `description`, `date`, `name`, `email`, `hits`, `submitter`, `sub_ip`, `filesize`, `version`, `homepage`, `active`) VALUES ('', 31, 1, '$file', 'Files/$file', 'Archived file', '2008-08-21 16:03:08', 'uname', 'uname@xxxxx.com', 0, 'uname', '128.174.129.50', '', '', '', 1);";
     echo "$query<br />";
    //}
  }   
 closedir($handle);
 echo "</p>";
}
?>

You can fill the values in with whatever you want, but for 900 files this made it real easy....
 
Gremmie







PostPosted: Fri Aug 22, 2008 4:44 pm Reply with quote

Nice job!
 
blith







PostPosted: Tue Aug 26, 2008 10:48 am Reply with quote

Thank you!
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> PHP

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©