Jump to content

Recommended Posts

Hey,

To start off , I am a total noob to PHP but I have done a fair share of research on it and tried making my own script.

 

The script I am trying to make is supposed to do the following

 

Check a website ( www.example.com ) for files

Ex:

It should check for this

www.random.com/1.wmv

www.random.com/1.avi

--------------------

www.random.com/2.wmv

www.random.com/2.avi

--------------------

www.random.com/3.wmv

www.random.com/3.avi

----------------------

ETC.....

The script should do this all the way up to a 100 and then echo back to me with information whether the file/video exists or not

 

 

 

 

 

Here's something I got so far

 

 

 

 

<?php

for ($i=1; $i<101; $i++)
{
echo "www.seajist.100webspace.net/".$i.".wmv<br>/n";
echo "www.seajist.100webspace.net/".$i.".avi<br>/n";
}


?>

 

 

Then I assume I should combine it with something like this

 

 

<?php
$filename = 'www.seajist.100webspace.net/71.avi';

if (file_exists($filename)) {
    echo "The file $filename exists";
} else {
    echo "The file $filename does not exist";
}
?> 

 

 

The problem is, I don't know how to sort of combine the two to work in the way I need it.

Could anyone possibly help =)

 

Thanks,

-SJ

 

Link to comment
https://forums.phpfreaks.com/topic/66287-solved-question-about-my-php-script/
Share on other sites

<?php

for ($i=1; $i<101; $i++)
{
$filename_avi = 'www.seajist.100webspace.net/'.$i.'.avi';
$filename_wmv = 'www.seajist.100webspace.net/'.$i.'.wmv';

  if (file_exists($filename_avi)) {
      echo "www.seajist.100webspace.net/".$i.".avi<br />/n";
  } else {
      echo "The file ".$filename." does not exist<br />/n";
  }
  if (file_exists($filename_wmv)) {
      echo "www.seajist.100webspace.net/".$i.".wmv<br />/n";
  } else {
      echo "The file ".$filename." does not exist<br />/n";
  }
}


?>

 

;)

http://us2.php.net/file_exists

file_exists is only for files on your server, it won't (AFAIK) work for URLS (which btw, need to begin with http://)

 

Try get_headers perhaps?

http://us2.php.net/manual/en/function.get-headers.php

I appreciate the quick reply but I am trying to check for files on a remote server so I would have to use the fopen()

 

Would this work?

 

 

<?php

for ($i=1; $i<101; $i++)
{
$filename_avi = 'www.seajist.100webspace.net/'.$i.'.avi';
$filename_wmv = 'www.seajist.100webspace.net/'.$i.'.wmv';

  if (fopen($filename_avi)) {
      echo "www.seajist.100webspace.net/".$i.".avi<br />/n";
  } else {
      echo "The file ".$filename." does not exist<br />/n";
  }
  if (fopen($filename_wmv)) {
      echo "www.seajist.100webspace.net/".$i.".wmv<br />/n";
  } else {
      echo "The file ".$filename." does not exist<br />/n";
  }
}


?>

you will have a long code using that try this first

http://us2.php.net/file_exists

file_exists is only for files on your server, it won't (AFAIK) work for URLS (which btw, need to begin with http://)

 

Try get_headers perhaps?

http://us2.php.net/manual/en/function.get-headers.php

 

 

If PHP has decided that filename specifies a local file, then it will try to open a stream on that file. The file must be accessible to PHP, so you need to ensure that the file access permissions allow this access. If you have enabled safe mode, or open_basedir further restrictions may apply.

 

If PHP has decided that filename specifies a registered protocol, and that protocol is registered as a network URL, PHP will check to make sure that allow_url_fopen is enabled. If it is switched off, PHP will emit a warning and the fopen call will fail.

 

Thought it might interest you..

 

http://uk.php.net/manual/en/function.fopen.php

<?php

  for ($i=1; $i<=100; $i++) {
    $filename_avi = 'www.seajist.100webspace.net/'.$i.'.avi';
    $filename_wmv = 'www.seajist.100webspace.net/'.$i.'.wmv';
    $ok = @get_headers($filename_avi);
    if (preg_match("|200|", $ok[0])) {
      echo "$filename_avi<br />/n";
    } else {
      echo "The file ".$filename_avi." does not exist<br />/n";
    }
    $ok = @get_headers($filename_wmv);
    if (preg_match("|200|", $ok[0])) {
      echo "$filename_wmv<br />/n";
    } else {
      echo "The file ".$filename_wmv." does not exist<br />/n";
    }
  }

?>

Take out the www.

 

Look at the URL you're trying to access.

www.seajist.100webspace.net/77.avi

Actually go to it in your browser. Is anything there? No.

 

Google "subdomains". Your site is not www.seajist.100webspace.net/ it is http://seajist.100webspace.net/

http://seajist.100webspace.net/77.avi HAS a file.

Yes I know but it isn't my site I am trying to look for files, it was just an example.

Here is the script I am currently using modified to my needs

 

<?php

  for ($i=1; $i<=100; $i++) {
    $filename_avi = 'http://www.xspand.ca/'.$i.'.avi';
    $filename_wmv = 'http://www.xspand.ca/'.$i.'.wmv';
    $ok = @get_headers($filename_avi);
    if (preg_match("|200|", $ok[0])) {
      echo "$filename_avi<br />/n";
    } else {
      echo "The file ".$filename_avi." does not exist<br />/n";
    }
    $ok = @get_headers($filename_wmv);
    if (preg_match("|200|", $ok[0])) {
      echo "$filename_wmv<br />/n";
    } else {
      echo "The file ".$filename_wmv." does not exist<br />/n";
    }
  }

?>

 

 

Either way, the PHP page returns blank

No I don't have an actual example

The example I was using to test was the seajist.100webspace.net/77.avi

 

 

Here is the error after removing @

 

 

Fatal error: Call to undefined function: get_headers() in /home/www/seajist.100webspace.net/omg.php on line 6

Are you using PHP4? get_headers is a PHP5 function only.

http://us.php.net/manual/en/function.get-headers.php

 

If you scroll down through the comments it looks like someone has posted a function to emulate it, that will work in 4.

You'll probably need to contact them to see how to get it switched to PHP5 for all your pages.

 

This is how I force PHP5 on my server on MT. It may/may not work for you, but it's worth a shot.

Save this code as simply .htaccess and upload it to your site:

AddHandler php5-script .php

You need to contact your host then. If it says the function is not found, then it sounds like you're running PHP4, not PHP5.

You can also try changing the file extension from .php to .php5 but I think it will have the same result. (Remove the .htaccess file tho.)

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.