wkdw1ll1ams Posted August 25, 2011 Share Posted August 25, 2011 im making a film site for my "personal use" and i have around 110 films to host on my server but i do not want to rite out the film names and hyperlink them to the AVI file because that would take all day. so i tried using this: http://pastebin.com/p8TiEfz5 this will allow me to go straight to the name of the AVI file i want to see. but i dont no where to put im new to php. could you put that code in here: http://www.heypasteit.com/clip/0060 Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/ Share on other sites More sharing options...
WebStyles Posted August 25, 2011 Share Posted August 25, 2011 you need something just a little more complex than that. That script you provided reads file names based on a given directory, but it seems you have a movie directory, and then each movie is contained within it's own folder. you need to test each folder with is_dir or something. Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1261899 Share on other sites More sharing options...
WebStyles Posted August 25, 2011 Share Posted August 25, 2011 try this (untested, may contain a few typos) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <html> <head> <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type" /> <meta name="author" content="FilmZilla"> <meta name="publisher" content="FilmZilla"> <meta name="copyright" content="FilmZilla"> <style type="text/css"> @import url(styles.css); </style> <title>FilmZilla</title> </head> <body> <div id="header">FilmZilla</div> <div id="bar_nav"> <ul> <a href="#">Home</a> <a href="Donate.html">Donate</a> </ul> </div> <div id="content_left"> <h1>Newest Films</h1> Planet 51 <BR> Scream 4 <BR> Xmen First Class </div> <!-- this is where the film links are ################################################## --> <div id="content"><h1>Films</h1> <?php $basefolder = opendir('/films/'); while (($folder = readdir( $basefolder)) !== false){ if (is_dir($folder)){ $subfolder = opendir('/films/'.$folder); while (($file = readdir( $subfolder)) !== false){ echo $folder . '/'. $file.'<br>'; echo '<a href="/films/'.$folder.'/'.$file.'">'.str_replace(".avi","",$file).'</a><br />'; } closedir( $subfolder ); } } closedir( $basefolder ); ?> <!--this is where the film links end ################################################## --> </div> <div id="bar_bottom2"><marquee>Films are all DVDRIP. Please donate. Do not take credit for these movies!</marquee></div> <div id="bar_bottom">© 2011 | Copyright © FileZilla</a></div> <!--[if IE]></div><![endif]--> <div style="text-align: center; font-size: 0.75em;">Copyright© FilmZilla</a>.</div></body> <link rel="shortcut icon" href="icon.ico"> <link rel="icon" type="image/gif" href="icon.png"> </html> Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1261904 Share on other sites More sharing options...
silkfire Posted August 25, 2011 Share Posted August 25, 2011 You're hosting copyrighted movies. Neat. Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1261912 Share on other sites More sharing options...
wkdw1ll1ams Posted August 26, 2011 Author Share Posted August 26, 2011 i get this all the way down the page: Warning: opendir(/films/,/films/) [function.opendir]: The system cannot find the file specified. (code: 2) in C:\xampp\htdocs\test.php on line 35 Warning: opendir(/films/) [function.opendir]: failed to open dir: No such file or directory in C:\xampp\htdocs\test.php on line 35 Warning: readdir() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\test.php on line 36 Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262089 Share on other sites More sharing options...
jcbones Posted August 26, 2011 Share Posted August 26, 2011 I found an old function in my library that was easily retrofitted for this application. I don't really like echo'ing out of functions, but it was the easiest way to solve the unknown depths the resulting multi-dem array. <?php function dirContents($dir) { if (is_dir($dir)) { if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { if(in_array($file,array('.','..'))) { continue; } if(is_dir($dir.'/'.$file)) { $contents[$dir.'/'.$file] = dirContents($dir.'/'.$file); } else { $contents[] = $dir . '/' . $file; } } closedir($dh); } } return $contents; } function processArray($array) { if(is_array($array)) { echo '<ol>'; foreach($array as $key => $value) { if(is_int($key)) { echo '<li><a href="'.$value.'">'.str_replace('/','',strstr(strrchr($value,'/'),'.',true)).'</a></li>'; } else { echo '<li><span style="font-weight:bold">' . $key . '</span>'; processArray($value); echo '</li>'; } } echo '</ol>'; } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <html> <head> <meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type" /> <meta name="author" content="FilmZilla"> <meta name="publisher" content="FilmZilla"> <meta name="copyright" content="FilmZilla"> <style type="text/css"> @import url(styles.css); </style> <title>FilmZilla</title> </head> <body> <div id="header">FilmZilla</div> <div id="bar_nav"> <ul> <a href="#">Home</a> <a href="Donate.html">Donate</a> </ul> </div> <div id="content_left"> <h1>Newest Films</h1> Planet 51 <BR> Scream 4 <BR> Xmen First Class </div> <!-- this is where the film links are ################################################## --> <div id="content"><h1>Films</h1> <?php $dir = 'test'; $files = dirContents($dir); processArray($files); ?> <!--this is where the film links end ################################################## --> </div> <div id="bar_bottom2"><marquee>Films are all DVDRIP. Please donate. Do not take credit for these movies!</marquee></div> <div id="bar_bottom">© 2011 | Copyright © FileZilla</a></div> <!--[if IE]></div><![endif]--> <div style="text-align: center; font-size: 0.75em;">Copyright© FilmZilla</a>.</div></body> <link rel="shortcut icon" href="icon.ico"> <link rel="icon" type="image/gif" href="icon.png"> </html> Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262106 Share on other sites More sharing options...
wkdw1ll1ams Posted August 26, 2011 Author Share Posted August 26, 2011 ok, im totally new to php and i hardly know how it works. do i paste that php in a new file and save it as "download.php" <a href="www.server.com/download.php">Scream 4</a> and the AVI file must be the same name as the hyperlink? Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262369 Share on other sites More sharing options...
jcbones Posted August 26, 2011 Share Posted August 26, 2011 In the above script I gave you, rename the $dir variable to the folder you want. ie. films. Sorry, I left it in test mode. $dir = 'path/to/folder'; //without trailing slash. The link will be the same name as the avi filename, without the extension, and will link directly to that file. Try it out, if you have questions on how it works, or the formatting, post the specific question. Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262386 Share on other sites More sharing options...
wkdw1ll1ams Posted August 26, 2011 Author Share Posted August 26, 2011 i will give this a try. ill edit this post if it works. ty. Edit: Notice: Undefined variable: contents in C:\xampp\htdocs\test.php on line 16 and line 16 is return $contents; Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262424 Share on other sites More sharing options...
jcbones Posted August 26, 2011 Share Posted August 26, 2011 Yep, that happens when you try to feed it a relative file path, with a slash BEFORE the first directory. $dir '/films/'; //incorrect. $dir './films'; //correct. $dir 'films'; //correct. $dir 'films/'; //incorrect. Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262440 Share on other sites More sharing options...
wkdw1ll1ams Posted August 26, 2011 Author Share Posted August 26, 2011 i removed the "/" at the end of films and still get Notice: Undefined variable: contents in C:\xampp\htdocs\test.php on line 16 Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262449 Share on other sites More sharing options...
WebStyles Posted August 26, 2011 Share Posted August 26, 2011 Notice: Undefined variable: contents means exactly what it says: It's a Notice, not an error, and it's saying that the variable contents ($contents) is undefined. Check where $contents is used and initialize it first to avoid this error. Apart from that, is the script working? Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262450 Share on other sites More sharing options...
wkdw1ll1ams Posted August 26, 2011 Author Share Posted August 26, 2011 the contents: $contents[] = $dir . '/films' . $file; $contents[$dir.'/films'.$file] = dirContents($dir.'/films'.$file); if(is_dir($dir.'/films'.$file)) { thats what i got. Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262455 Share on other sites More sharing options...
WebStyles Posted August 26, 2011 Share Posted August 26, 2011 I know what you have, I saw your code before. $contents[] is an array that was not initialized. Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262456 Share on other sites More sharing options...
wkdw1ll1ams Posted August 26, 2011 Author Share Posted August 26, 2011 so how do i initialized it? Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262457 Share on other sites More sharing options...
WebStyles Posted August 26, 2011 Share Posted August 26, 2011 $contents = array(); Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262458 Share on other sites More sharing options...
jcbones Posted August 26, 2011 Share Posted August 26, 2011 Ummm, I wrote the script, and I ALSO gave you the cure. If you read, it will come. Yep, that happens when you try to feed it a relative file path, with a slash BEFORE the first directory. $dir '/films/'; //incorrect. $dir './films'; //correct. $dir 'films'; //correct. $dir 'films/'; //incorrect. Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262461 Share on other sites More sharing options...
wkdw1ll1ams Posted August 26, 2011 Author Share Posted August 26, 2011 i didnt understand what you mean because i tried: $dir './films'; //correct. $dir 'films'; //correct. ./films: if(is_dir($dir.'/films'.$file)) { $contents[$dir.'/films'.$file] = dirContents($dir'/films'.$file); } else { $contents[] = $dir . '/films' . $file; And: if(is_dir($dir.'films'.$file)) { $contents[$dir.'/films'.$file] = dirContents($dir.'films'.$file); } else { $contents[] = $dir . 'films' . $file; Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262463 Share on other sites More sharing options...
WebStyles Posted August 26, 2011 Share Posted August 26, 2011 oh man.... Do you have ANY understanding of variables at all ? Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262464 Share on other sites More sharing options...
WebStyles Posted August 27, 2011 Share Posted August 27, 2011 you're trying to build a simple path to some files... you have been told that the base directory MUST be './films' or 'films'... if you want a path like films/moviename/movie.avi and you store './films' in a variable called $dir.. then the path will be: $dir.'/moviename/movie.avi' Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262465 Share on other sites More sharing options...
wkdw1ll1ams Posted August 27, 2011 Author Share Posted August 27, 2011 $contents[] = $dir . '/films' . $file; if(is_dir($dir.'/films'.$file)) { $contents[$dir.'/films'.$file] = dirContents($dir.'/films'.$file); or $contents[] = $dir . '/scream4/scream4.avi' . $file; if(is_dir($dir.'/scream4/scream4.avi'.$file)) { $contents[$dir.'/films'.$file] = dirContents($dir.'/scream4/scream4.avi'.$file); like that? Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262469 Share on other sites More sharing options...
WebStyles Posted August 27, 2011 Share Posted August 27, 2011 please think about what's happening when you do this: if(is_dir($dir.'/scream4/scream4.avi'.$file)) { you seem very confused. Do you understand that a variable holds a piece of information, in this case a string (sequence of characters) ? so $file holds the file's name.... and... is_dir tests to see if the input path is a directory (folder) now look at the code above again, and tell me what's wrong with it. Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262470 Share on other sites More sharing options...
wkdw1ll1ams Posted August 27, 2011 Author Share Posted August 27, 2011 hhmm. the code is wrong because the directory "films" is missing? Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262473 Share on other sites More sharing options...
WebStyles Posted August 27, 2011 Share Posted August 27, 2011 ok, back to basics... what would be the result of this? $var = "whatever"; echo $var . ' xxx ' . $var . ' xxx'; Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262474 Share on other sites More sharing options...
wkdw1ll1ams Posted August 27, 2011 Author Share Posted August 27, 2011 i havnt got a clue Quote Link to comment https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/#findComment-1262476 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.