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
https://forums.phpfreaks.com/topic/79921-file_exists/
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
https://forums.phpfreaks.com/topic/79921-file_exists/#findComment-404800
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
https://forums.phpfreaks.com/topic/79921-file_exists/#findComment-404814
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
https://forums.phpfreaks.com/topic/79921-file_exists/#findComment-404817
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.