0

Hi!

I want to check if some file on some other server exists. I have this code (but something is wrong with it):

<?php
$notworking=array();
$false=0;
$link="http://uploads.mp3songurls.com/";
$files=glob("genre/*.xml");
foreach($files as $file){
$xml=new SimpleXMLElement($file,null,true);
foreach($xml as $info){
if(fopen($link.$info->link.".mp3","r")==false){
$false++;
$notworking[$false]=$info->name." => ".$info->author;
}
}
}
if($false>0){
$file=fopen("notworking.txt","w");
for($i=1;$i<=$false;$i++){
fwrite($file,$notworking[$i]."\r\n");
}
fclose($file);
echo "(some songs don't exist: <a href=\"javascript:void(0)\" onclick=\"window.open('notexist.php','popupWindow','height=500,width=600,left=30,top=40,toolbar=no,location=no,status=no,menubar=no,scrollbars=no');\">$false</a>)";
}else{
if(file_exists("notworking.txt"))
unlink("notworking.txt");
echo "(everything's OK)";
}
?>

I'm getting "(everything's OK)", but one file isn't OK (it doesn't exist). Is there some error in code or what? Thanks a lot! (PS. And with XML file is everything OK)

Edited by ivan3510: n/a

3
Contributors
8
Replies
9
Views
6 Years
Discussion Span
Last Post by ivan3510
0

No, it's not that. But when I open this file, it automatically redirects me to home page. Is this problem because of redirection, or?

0

Possible. I think fopen follows redirects. IIRC there may be a way to set maximum number of redirects to follow. You'd have to google for it.

0

I found something, but it doesn't work.

<?php
$redirect=array('http'=>array('max_redirects'=>'0')); //I tried to add only 0
$context=stream_context_create($redirect);
$file=fopen("http://uploads.mp3songurls.com/1101746.mp3","r",false,$context);
if($file==false)
echo "false";
else echo "true";
?>

I'm getting true. What's mistake?

Edited by ivan3510: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.