Jump to content

[SOLVED] Question about my PHP Script


sjxx

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
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";
  }
}


?>

 

;)

Link to comment
Share on other sites

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";
  }
}


?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?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";
    }
  }

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.)

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.