tbare Posted December 7, 2007 Share Posted December 7, 2007 Hello, all... i've got a list of files and i'm trying to have to manually define as little as possible... here's what i've got: <?php //new file $file = "Abbott and Costello - Who's On First.avi"; $title = "Abbott and Costello - Who's On First"; $thumb = "wof_thumb.jpg"; list($width, $height) = getimagesize("$thumb_path/$thumb"); $thumb_width = "$width"; $thumb_height = "$height"; include("text_files/video_info.php"); $size = filesize("$file_path/$file"); $file = preg_replace("/'/", "'" , $file); $title = preg_replace("/'/", "'" , $title); print "<tr><td>\n"; print "<a href='humor_video_play.php?file=$file&title=$title'>\n<img border='0' src='$thumb_path/$thumb' width='$thumb_width' height='$thumb_height' alt=' '></a></td>\n"; print "<td><a href='humor_video_play.php?file=$file&title=$title'>$title</a><br>\n"; print "<a href='$file_path/$file'>download file</a> | file size: "; include("text_files/filesize.php"); print "$size<br>\n"; print "duration : "; print "$duration\n"; print "</td></tr>\n"; ?> where video_info.php contains: <?php $movie = new ffmpeg_movie('files/video/' . $file); $video_height = $movie->getFrameHeight(); $video_width = $movie->getFrameWidth(); $duration = $movie->getDuration(); $minutes = floor($duration / 60); $seconds = round($duration % 60,2); if($seconds < 10){ $seconds = "0" . $seconds; } $duration = $minutes.':'.$seconds; ?> then the same thing for the next file and so on... this works great, but i'm wondering if there's a better way to do this to where i'm not using <rant>SO MUCH FREAKIN CODE!</rant> i'm open to suggestions... someone suggested using an array, and i'm open to that... i just want this to be as compact as possible, basically... Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/80641-solved-is-this-the-best-way-to-do-this/ Share on other sites More sharing options...
boushley Posted December 7, 2007 Share Posted December 7, 2007 Well, if you can guarantee the naming convention will be the title like that... you can parse the title by using substrings to cut off the .avi. You could also write an array like this. $files = array( array( 'file'=>'Abbot and Costello - Who's On First.avi', 'title'=>'Abbot and Costello- Who's on First' 'thumb'=>'wof_thumb.jpg' ) array( 'file'=>'Abbot and Costello - Who's On First2.avi', 'title'=>'Abbot and Costello- Who's on First2' 'thumb'=>'wof_thumb2.jpg' ) ); And then turn the printing into a function, and use something like this. foreach($files as $file){ printLinkRow($file); } That way you can reuse most of your code. Quote Link to comment https://forums.phpfreaks.com/topic/80641-solved-is-this-the-best-way-to-do-this/#findComment-408972 Share on other sites More sharing options...
tbare Posted December 7, 2007 Author Share Posted December 7, 2007 i like that... so, using that array style, i could do this: <?php //create the array as in your example here foreach($files as $file){ printLinkRow($file); print "<tr><td>\n"; print "<a href='humor_video_play.php?file=$file&title=$title'>\n<img border='0' src='$thumb_path/$thumb' width='$thumb_width' height='$thumb_height' alt=' '></a></td>\n"; print "<td><a href='humor_video_play.php?file=$file&title=$title'>$title</a><br>\n"; print "<a href='$file_path/$file'>download file</a> | file size: "; include("text_files/filesize.php"); print "$size<br>\n"; print "duration : "; print "$duration\n"; print "</td></tr>\n"; } ?> one thing i noticed there is that after 'file'=>'blah.avi' you have a comma, but not after title... should there be one there? (again, i'm new to arrays...) thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/80641-solved-is-this-the-best-way-to-do-this/#findComment-408977 Share on other sites More sharing options...
boushley Posted December 7, 2007 Share Posted December 7, 2007 Yes there should be LOL... good catch. And I guess you could do this foreach($files as $file){ printLinkRow($file); print "<tr><td>\n"; print "<a href='humor_video_play.php?file=$file&title=$title'>\n<img border='0' src='$thumb_path/$thumb' width='$thumb_width' height='$thumb_height' alt=' '></a></td>\n"; print "<td><a href='humor_video_play.php?file=$file&title=$title'>$title</a><br>\n"; print "<a href='$file_path/$file'>download file</a> | file size: "; include("text_files/filesize.php"); print "$size<br>\n"; print "duration : "; print "$duration\n"; print "</td></tr>\n"; } But I was suggesting something like this <?php include("text_files/filesize.php"); $files = array( array( 'file'=>'Abbot and Costello - Who\'s On First.avi', 'title'=>'Abbot and Costello- Who\'s on First', 'thumb'=>'wof_thumb.jpg' ) array( 'file'=>'Abbot and Costello - Who\'s On First2.avi', 'title'=>'Abbot and Costello- Who\'s on First2', 'thumb'=>'wof_thumb2.jpg' ) ); function printLinkRow($file){ $message = "<tr><td>\n"; $message .= "<a href='humor_video_play.php?file=$file&title=$title'>\n<img border='0' src='$thumb_path/$thumb' width='$thumb_width' height='$thumb_height' alt=' '></a></td>\n"; $message .= "<td><a href='humor_video_play.php?file=$file&title=$title'>$title</a><br>\n"; $message .= "<a href='$file_path/$file'>download file</a> | file size: "; //Note, you don't want to include this file over & over $message .= "$size<br>\n"; $message .= "duration : "; $message .= "$duration\n"; $message .= "</td></tr>\n"; return($message); } foreach($files as $file){ print(printLinkRow($file)); } P.S. Threw the backslashes in so that we didn't prematurely end the string. (Single quotes are a little faster since php doesn't try to parse through them looking for variables. Quote Link to comment https://forums.phpfreaks.com/topic/80641-solved-is-this-the-best-way-to-do-this/#findComment-408988 Share on other sites More sharing options...
tbare Posted December 7, 2007 Author Share Posted December 7, 2007 <?php include("text_files/filesize.php"); $file_path = "files/video"; $thumb_path = "$file_path/thumbs"; $files = array( array( 'file'=>'Abbot and Costello - Who\'s On First.avi', 'title'=>'Abbot and Costello- Who\'s on First', 'thumb'=>'wof_thumb.jpg' ) array( 'file'=>'getamac-misprint.avi', 'title'=>'Mac Ad: Misprint', 'thumb'=>'getamac-misprint_thumb.png'; ) ); function printLinkRow($file){ $message = "<tr><td>\n"; $message .= "<a href='humor_video_play.php?file=$file&title=$title'>\n<img border='0' src='$thumb_path/$thumb' width='$thumb_width' height='$thumb_height' alt=' '></a></td>\n"; $message .= "<td><a href='humor_video_play.php?file=$file&title=$title'>$title</a><br>\n"; $message .= "<a href='$file_path/$file'>download file</a> | file size: "; $message .= "$size<br>\n"; $message .= "duration : "; $message .= "$duration\n"; $message .= "</td></tr>\n"; return($message); } foreach($files as $file){ print(printLinkRow($file)); } ?> returns: Quote Parse error: syntax error, unexpected T_ARRAY, expecting ')' in /home/tbare/wannafork/text_files/humor_video2.php on line 12 ?? i don't know enough about arrays to know why what you showed didn't work... Quote Link to comment https://forums.phpfreaks.com/topic/80641-solved-is-this-the-best-way-to-do-this/#findComment-409000 Share on other sites More sharing options...
tbare Posted December 7, 2007 Author Share Posted December 7, 2007 also... why do i not want to include the filesize.php file there every time? just including it once didn't want to work... here's what it contains: <?php //make file sizes user friendly by converting to KB, MB, or GB if($size >= 1024 && $size < 1048576) { //make KB $size = number_format(($size) / 1024, 2); $size = "$size KB\n"; } else if($size >= 1048576 && $size < 1073741824) { //make MB $size = number_format(($size) / 1048576, 2); $size = "$size MB\n"; } else if($size >= 1073741824) { //make GB $size = number_format(($size) / 1073741824, 2); $size = "$size GB\n"; } else { //leave as bytes. $size = "$size bytes"; } ?> just wondering... i would think that i would have to include that after i set *$size = filesize("$file_path/$file");* ?? Quote Link to comment https://forums.phpfreaks.com/topic/80641-solved-is-this-the-best-way-to-do-this/#findComment-409030 Share on other sites More sharing options...
boushley Posted December 7, 2007 Share Posted December 7, 2007 You were right about the include... sorry I didn't think about what I was doing very well As for the parse error... I forgot another, LOL... I'm just messing those up all over today. <?php $files = array( array( 'file'=>'Abbot and Costello - Who\'s On First.avi', 'title'=>'Abbot and Costello- Who\'s on First', 'thumb'=>'wof_thumb.jpg' ), //forgot this comma array( 'file'=>'Abbot and Costello - Who\'s On First2.avi', 'title'=>'Abbot and Costello- Who\'s on First2', 'thumb'=>'wof_thumb2.jpg' ) ); function printLinkRow($file){ $message = "<tr><td>\n"; $message .= "<a href='humor_video_play.php?file=$file&title=$title'>\n<img border='0' src='$thumb_path/$thumb' width='$thumb_width' height='$thumb_height' alt=' '></a></td>\n"; $message .= "<td><a href='humor_video_play.php?file=$file&title=$title'>$title</a><br>\n"; $message .= "<a href='$file_path/$file'>download file</a> | file size: "; include("text_files/filesize.php"); //put this back in $message .= "$size<br>\n"; $message .= "duration : "; $message .= "$duration\n"; $message .= "</td></tr>\n"; return($message); } foreach($files as $file){ print(printLinkRow($file)); } Quote Link to comment https://forums.phpfreaks.com/topic/80641-solved-is-this-the-best-way-to-do-this/#findComment-409106 Share on other sites More sharing options...
tbare Posted December 7, 2007 Author Share Posted December 7, 2007 <?php $file_path = "files/video"; $thumb_path = "$file_path/thumbs"; $files = array( array( 'file'=>'Abbot and Costello - Who\'s On First.avi', 'title'=>'Abbot and Costello- Who\'s on First', 'thumb'=>'wof_thumb.jpg' ), array( 'file'=>'CircleCircleDotDot.avi', 'title'=>'I got my cootie shot.', 'thumb'=>'CircleCircleDotDot_thumb.png' ) ); function printLinkRow($file){ list($thumb_width, $thumb_height) = getimagesize("$thumb_path/$thumb"); $message = "<tr><td>\n"; $message .= "<a href='humor_video_play.php?file=$file&title=$title'>\n<img border='0' src='$thumb_path/$thumb' width='$thumb_width' height='$thumb_height' alt=' '></a></td>\n"; $message .= "<td><a href='humor_video_play.php?file=$file&title=$title'>$title</a><br>\n"; $message .= "<a href='$file_path/$file'>download file</a> | file size: "; include("text_files/filesize.php"); $message .= "$size<br>\n"; $message .= "</td></tr>\n"; return($message); } foreach($files as $file){ print(printLinkRow($file)); } and i get this: http://www.wannafork.com/humor_video2.php originally, looked like this: http://www.wannafork.com/humor_video.php obviously, the latter has more files, but you get the idea... Quote Link to comment https://forums.phpfreaks.com/topic/80641-solved-is-this-the-best-way-to-do-this/#findComment-409125 Share on other sites More sharing options...
tbare Posted December 7, 2007 Author Share Posted December 7, 2007 any idea why? Quote Link to comment https://forums.phpfreaks.com/topic/80641-solved-is-this-the-best-way-to-do-this/#findComment-409227 Share on other sites More sharing options...
JacobYaYa Posted December 7, 2007 Share Posted December 7, 2007 Since $title etc are now stored in an array you need to change your echos from $title to $file['title'] etc EDIT: Not echos....I mean $message part of your function. Quote Link to comment https://forums.phpfreaks.com/topic/80641-solved-is-this-the-best-way-to-do-this/#findComment-409336 Share on other sites More sharing options...
tbare Posted December 8, 2007 Author Share Posted December 8, 2007 thanks, JacobYaYa... now i can't call the functions filesize() or getimagesize() w/o getting an error... this is getting to be a headache... but i want to get this working so i can use pagination... Quote Link to comment https://forums.phpfreaks.com/topic/80641-solved-is-this-the-best-way-to-do-this/#findComment-409452 Share on other sites More sharing options...
tbare Posted December 8, 2007 Author Share Posted December 8, 2007 got it... (finally) <?php $files = array( array( 'file'=>'Abbott and Costello - Who\'s On First.avi', 'title'=>'Abbott and Costello- Who\'s on First', 'thumb'=>'wof_thumb.jpg' ), array( 'file'=>'CircleCircleDotDot.avi', 'title'=>'I got my cootie shot.', 'thumb'=>'CircleCircleDotDot_thumb.png' ) ); function printLinkRow($file){ $file_path = "files/video"; $thumb_path = "$file_path/thumbs"; $filez = $file['file']; $title = $file['title']; $thumb = $file['thumb']; $size = filesize("$file_path/$filez"); list($thumb_width, $thumb_height) = getimagesize("$thumb_path/$thumb"); $filez = preg_replace("/'/", "'" , $filez); $title = preg_replace("/'/", "'" , $title); $message = "<tr><td>\n"; $message .= "<a href='humor_video_play.php?file=$filez&title=$title'>\n<img border='0' src='$thumb_path/$thumb' width='$thumb_width' height='$thumb_height' alt=' '></a></td>\n"; $message .= "<td><a href='humor_video_play.php?file=$filez&title=$title'>$title</a><br>\n"; $message .= "<a href='$file_path/$filez'>download file</a> | file size: "; include("text_files/filesize.php"); $message .= "$size<br>\n"; $message .= "</td></tr>\n"; return($message); } foreach($files as $file){ print(printLinkRow($file)); } ?> seen @http://www.wannafork.com/humor_video2.php eventually, when i get the rest of the videos put in the array, i'll make it live, then on to pagination! (woohoo).. Quote Link to comment https://forums.phpfreaks.com/topic/80641-solved-is-this-the-best-way-to-do-this/#findComment-409473 Share on other sites More sharing options...
tbare Posted December 8, 2007 Author Share Posted December 8, 2007 the rest of the videos are on now.. (just took too long, couldn't just modify the last post..) check 'em out if you wanna.. if you see any problems, let me know... http://www.wannafork.com/humor_video2.php thanks for all your help!! Quote Link to comment https://forums.phpfreaks.com/topic/80641-solved-is-this-the-best-way-to-do-this/#findComment-409490 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.