Jump to content

Recommended Posts

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  :shrug: im new to php.

 

could you put that code in here:

 

http://www.heypasteit.com/clip/0060

Link to comment
https://forums.phpfreaks.com/topic/245688-help-with-this-code-please/
Share on other sites

  • Replies 63
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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.

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>

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

 

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>

 

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.

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?

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.

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;

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'

$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?

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.