intenseone345 Posted March 2, 2011 Share Posted March 2, 2011 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 https://forums.phpfreaks.com/topic/229383-php-code-question/ Share on other sites More sharing options...
ZacTopher Posted March 2, 2011 Share Posted March 2, 2011 What's the output when you echo out the full path? Link to comment https://forums.phpfreaks.com/topic/229383-php-code-question/#findComment-1181884 Share on other sites More sharing options...
intenseone345 Posted March 2, 2011 Author Share Posted March 2, 2011 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 https://forums.phpfreaks.com/topic/229383-php-code-question/#findComment-1181890 Share on other sites More sharing options...
intenseone345 Posted March 2, 2011 Author Share Posted March 2, 2011 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 https://forums.phpfreaks.com/topic/229383-php-code-question/#findComment-1181942 Share on other sites More sharing options...
ZacTopher Posted March 2, 2011 Share Posted March 2, 2011 I won't say this for sure, it's more of a guess really, but I don't think dir() works across servers.. If it did it would be a major security hole letting anyone getting acces to a list of dirs/files on any site they want Link to comment https://forums.phpfreaks.com/topic/229383-php-code-question/#findComment-1181946 Share on other sites More sharing options...
intenseone345 Posted March 2, 2011 Author Share Posted March 2, 2011 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 https://forums.phpfreaks.com/topic/229383-php-code-question/#findComment-1181948 Share on other sites More sharing options...
kenrbnsn Posted March 2, 2011 Share Posted March 2, 2011 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 https://forums.phpfreaks.com/topic/229383-php-code-question/#findComment-1181955 Share on other sites More sharing options...
ZacTopher Posted March 2, 2011 Share Posted March 2, 2011 Nice idea Ken! I see i have alot to learn about teaching/finding solutions on other peoples scripts. I only see solutions like these on my own projects now :-/ Hopefully that'll come with practice Link to comment https://forums.phpfreaks.com/topic/229383-php-code-question/#findComment-1181959 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.