Jump to content

script to see if the file exists or not


Sangha-08

Recommended Posts

hi,

 

i just wanted to add a new function in my script that fetches the flv file from veoh.com . I want to add a function if file exists or not.

I just want a simple function to see if the file exists or not , if i doesn't then i want to load a video thats hosted on my server...

 

any suggestions ?

Link to comment
Share on other sites

$filepath=path_to_your_file;

if(file_exists($filepath)){

      //do whatever you want

}

 

oops sorry .. I misread ur post. I thought the file you wanna chk is on your server :)

 

I think you can't do it by PHP cause php is server side language. So it has no idea what is happening in outer world other than its server. So you have to go for any client side language like Javascript etc.

Link to comment
Share on other sites

Here's a quick and dirty function that will work using file_get_contents. Although I remember reading information about this previously that there are some specific issues when doing this. It worked n some simple tests that I ran though.

 

function httpFileExists($url) {

  if (!@file_get_contents($url)) { return false; }
  return true;

}

Link to comment
Share on other sites

Here's a quick and dirty function that will work using file_get_contents. Although I remember reading information about this previously that there are some specific issues when doing this. It worked n some simple tests that I ran though.

 

function httpFileExists($url) {

  if (!@file_get_contents($url)) { return false; }
  return true;

}

 

That could be bad because it has to download the whole file first.  Give me a second and I'll see if I can think of something.

Link to comment
Share on other sites

That function is way too puffed with unneeded stuff. Try this:

 

<?php

function http_exists($url) //$url must be valid, starts with http://
{
$headers = get_headers($url)
if($headers === FALSE)
	return FALSE;
return (strtolower($headers[0]) == 'http/1.1 404 not found');
}
?>

 

Orio.

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.