Jump to content

file_exists


Bmen

Recommended Posts

Please help with this one... I have only one single hair left and it is feeling threatened.....

 

I have 2 domains

 

domain 1 has thousands of images

 

I draw images from domain 1 into domain 2

 

Problem :

 

when I try to check if an image exists on domain 1 from domain 2 file_exists() does not work across the 2 domains (works fine locally but not on the server)

 

I have set safe_mode to off but this does not help

 

here is an example of the code I am using

 

if(file_exists('http://www.domain1.com.au')){

echo 'file_exists';

}else{

echo 'file does not exist';

}

 

any help is greatly appreciated

 

Link to comment
Share on other sites

Try this tell me it works or not... looks like we are on same track, i got 5000+ images too transfer  ;D

<?php
$file = "http://www.domain1.com.au"; // i added file name here and it shows exists...
$file_headers = @get_headers($file);
if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
$exists = false;
echo "file does not exists";
}
else {
$exists = true;
echo "file exists";
} ?>

Link to comment
Share on other sites

Thank you for your reply but I have to say sorry on 2 counts

 

1) I should have said the files are http://www.domain1.com.au/image.jpg and not just the url

 

and

 

2) I have tried get_headers and I get nothing returned

 

If I remove the @ symbol I get call to undefined function get_headers.

 

is there a way to turn this on in the ini file >

 

 

Link to comment
Share on other sites

What i am doing here is listing all of the files in a directory and making that into a variable.

Then i print each filename into a hidden input in a form which points to

 

http://www.newdomain.com/file_check.php

 

Which will be explained later.

Here is what should be contained in the file http://www.olddomain.com/file_send.php

<?php
$files_list = glob("*", GLOB_MARK);
$files_array = explode("/", $files_list);
print '<form action=http://www.newdomain.com/file_check.php method=post>';
foreach($files_array as $file) {
	print '<input type=hidden name=file value=' . $file . ' />';
}
print '<input name=submit type=submit value=Check />';
print '</form>';
?>

Now that we have populated the form and sent it we must check each file on the other end.

This is the file mentioned earlier (http://www.newdomain.com/file_check.php).

Here we get the form data if it is submitted and check it

<?php
if($_POST['submit']) {
	foreach($_POST['file'] as $file) {
		if(file_exists($file)) {
			print $file . ' does not exist';
		}
		else {
			print $file . ' does exist';
		}
	}
}
else {
	headers('location:http://www.olddomain.com/file_send.php');
}
?>

NOTE: This is not dialup friendly. You will be submitting as much data as you have file names.

 

I have not tested this but i am sure it will work.

You will probably have to change some things because this is only a basic thing

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.