Bmen Posted December 3, 2007 Share Posted December 3, 2007 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 More sharing options...
~n[EO]n~ Posted December 3, 2007 Share Posted December 3, 2007 Try this tell me it works or not... looks like we are on same track, i got 5000+ images too transfer <?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 More sharing options...
Bmen Posted December 3, 2007 Author Share Posted December 3, 2007 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 More sharing options...
mr_mind Posted December 3, 2007 Share Posted December 3, 2007 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 More sharing options...
Bmen Posted December 3, 2007 Author Share Posted December 3, 2007 Thank you for your help. Problem solvered Thanks heaps and have a great xmas Link to comment https://forums.phpfreaks.com/topic/79921-file_exists/#findComment-404871 Share on other sites More sharing options...
mr_mind Posted December 3, 2007 Share Posted December 3, 2007 Your welcome Link to comment https://forums.phpfreaks.com/topic/79921-file_exists/#findComment-404876 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.