Jump to content

PHP code question


intenseone345

Recommended Posts

Hello, what this script does is it goes to a labeled directory and picks a random flv file to play, it works great with jw player on the same server.

my problem is i have a "sever-A" that dont allow flv files, and a "server-B" that does.

im trying to use this script to call random flv's from server-b to server-a to play them.

but i get a browser error "directory not found".

Is there something im missing here or its just not possible to call to another server using php?

Here is a simple test page i was experimenting with below, any input on this would be greatly appreciated, thanks.

 

<?php $imglist=''; 
//$img_folder is the variable that holds the path to the swf files. 
// see that you dont forget about the "/" at the end 
$img_folder = "http://www.mywebsite.com/dumppy"; mt_srand((double)microtime()*1000); 
//use the directory class 
$imgs = dir($img_folder); 
//read all files from the directory, ad them to a list 
while ($file = $imgs->read()) { 
if (eregi("flv", $file)) $imglist .= "$file "; } closedir($imgs->handle); 
//put all images into an array 
$imglist = explode(" ", $imglist); 
$no = sizeof($imglist)-2; 
//generate a random number between 0 and the number of images 
$random = mt_rand(0, $no); $image = $imglist[$random]; 
//display random swf 


?>


<HTML>
<HEAD>
<TITLE>Untitled</TITLE>
<META NAME="GENERATOR" CONTENT="MAX's HTML Beauty++ 2004">
</HEAD>

<BODY>

<p><?echo $img_folder.$image?></p>

</BODY>
</HTML>

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Hi, i just get the same "directory not found " error, i dont know if the code runs so fast that it dont get a chance to search the other server and just gives a error instead, like i say it works perfect using it within the same server but they got something against FLV files being stored on there system.

Link to comment
Share on other sites

This small php random playlist script works great set up the same way as the script above with outside the server url's, so its a mystery as to why the first script wont work in the same way.

 

<?php
// Create an array with all the filenames
$urls = array(
  "http://www.myotherwebsite.com/dumppy/spaceshuttlelaunch.flv",
  "http://www.myotherwebsite/dumppy/shuttlelaunchendeavour.flv",
  "http://www.myotherwebsite/dumppy/launchtomeco.flv"
);

// Select a random filename from the array
$random_file = $urls[ array_rand($urls) ];


?>
<HTML>
<HEAD>
<TITLE>Untitled</TITLE>
<META NAME="GENERATOR" CONTENT="MAX's HTML Beauty++ 2004">
</HEAD>

<BODY>

<p><?php echo $random_file; ?></p>

</BODY>
</HTML>

Link to comment
Share on other sites

Hello, yes thanks for your reply and this is true what you say about security.

im probly better off choosing the playlist script below, i just thought it would be great to link to a my flv directory rather than making a "fixed playlist".

of coarse the fixed playlist would be the way to go if im going across servers.

thanks again.

Link to comment
Share on other sites

What you may want to do is to create a small script on the server where the files reside. The output of this script would be a list of the files you want. You would then invoke this script using curl(), file(), or file_get_contents() to get the list. Then you can proceed with your code. Of course you should put some sort of security into the script so that it wouldn't work for anybody but your calling script.

 

Ken

Link to comment
Share on other sites

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.