I think I am goin about this all wrong

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Shamu
Forum Newbie
Posts: 5
Joined: Thu Aug 08, 2002 7:55 pm
Contact:

I think I am goin about this all wrong

Post by Shamu »

Hello,

I am trying to make a php script to when given a catagory from a web page will index the directory and from the given formats send the data to a mysql database. I have tested and edited extensively and scoured the net for eamples yet unsuccessful. I found this website and alot of people seem to be very helpful. I would apprieicate and help or pointers on how to get this working very much.

<?
//movie indexer
$dbase = mysql_connect("localhost","user","password");
mysql_select_db("family",$dbase);
//get files in the current directory
$handle=opendir('.');
while ($file = readdir($handle)) {
if (substr($file, -3) == "avi" | substr($file, -3) ==
"mpg" | substr($file, -3) == "mov" | substr($file, -3) == "asf") {
$files[] = array(name => $file, size =>
intval(filesize($file)/1024));
}

}
closedir($handle);
sort($files);

//loop through the the files to enter into the database
for ($i = 0; $i <= count($files)-1; $i++) {
$time = date ("mdY-His");
$moviename = "$files";
$filesize = "$size";
$query = "INSERT INTO movies (moviename, filesize,, time, catagory)";
$query .= "VALUES ('$moviename', '$filesize', '$time', '$catagory')";
}
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

only a few simple mistakes ;)
  • a logical-or is expressed not by | but ||
  • $moviename = "$files"; and $filesize = "$size"; <- from where?
sort($files); <- why sorting the files array and how?

Code: Select all

<?php
//movie indexer 
$dbase = mysql_connect("localhost","user","pass"); 
mysql_select_db("family", $dbase); 
//get files in the current directory 
$handle=opendir('.'); 
while ($file = readdir($handle))
&#123; 
	if (substr($file, -3) == "avi" || substr($file, -3) == "mpg" || substr($file, -3) == "mov" || substr($file, -3) == "asf")
	&#123; 
		$files&#1111;] = array(name => $file, size =>intval(filesize($file)/1024)); 
	&#125; 
&#125; 
closedir($handle); 

//loop through the the files to enter into the database 
foreach($files as $movie)
&#123;
	$catagory = ""; // ???
	$time = date("mdY-His"); 
	$query = "INSERT INTO movies (moviename, filesize, time, catagory)"; 
	$query .= "VALUES ('&#123;$movie&#1111;"name"]&#125;', '&#123;$movie&#1111;"size"]&#125;', $time, '$catagory')";
	print($query."<br/>");
	mysql_query($query, $dbase) or die(mysql_error());
&#125; 
?>
I don't know how $catagory is set so I left it "".
There's no code that prevents a file from beeing inserted twice (maybe you table definition sets moviename to be unique)

---
code not tested (not even by compiler ;) )
Shamu
Forum Newbie
Posts: 5
Joined: Thu Aug 08, 2002 7:55 pm
Contact:

Post by Shamu »

awesome help!. This is one of the first php scripts I have ever written from scratch. I plan to evolve it to look for the filename in the database and if it is their then move onto the next one. Not for sure on how that is going to work but I will get their. I even plan to have Mogrify or smpeg grab the first frame from each movie and add it as a thumbnail.

I searched and searched and while I could find some things that would do this with images I found nothing php that would do it to mysql... the reason for mysql is because I want all the images in 1 directory and I am not sure if I am going to link to the movies using http (with mod throttle) or with ftp (awesome user control but can be hard to support) so this way I have the file names I can do it however I want. I would like to make it so I can add it to your archive when I am done. I am sure some people can find uses for it.... hmm i babbly to much i doubt anyone cares about all this crap

anyway Thanks for the help and your time!

Beunos Nachos,

Jeremy
Post Reply