dreamwest Posted May 12, 2009 Share Posted May 12, 2009 Im trying to use file exists for a file thats located on another server, the file does exist there but file_exists() function says it doesnt $file = "http://site_2.com/file.jpg"; if (file_exists($file)) { echo 'File found.'; }else{ echo 'File not found.'; exit(); } Quote Link to comment https://forums.phpfreaks.com/topic/157793-file_exists/ Share on other sites More sharing options...
Dathremar Posted May 12, 2009 Share Posted May 12, 2009 If You are trying to access on different domain then the host of the script, I guess it is considered as cross site scripting and it is not allowed. Quote Link to comment https://forums.phpfreaks.com/topic/157793-file_exists/#findComment-832228 Share on other sites More sharing options...
PFMaBiSmAd Posted May 12, 2009 Share Posted May 12, 2009 From the documentation for the funciton you are using - Tip As of PHP 5.0.0, this function can also be used with some URL wrappers. Refer to List of Supported Protocols/Wrappers for a listing of which wrappers support stat() family of functionality. The http protocol does not support any of the stat() functions. You should be able to use the http_get() function to test if a remote file exists - http://php.net/http_get Quote Link to comment https://forums.phpfreaks.com/topic/157793-file_exists/#findComment-832311 Share on other sites More sharing options...
dreamwest Posted May 12, 2009 Author Share Posted May 12, 2009 Im trying to create a download file for flv files, this code below displays an onscreen out put but i need to download the file $file = "http://site_2.com/files/video.flv"; header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Cache-Control: private', false); header('Content-Type: application/zip'); header('Content-Disposition: attachment; filename="name";'); header('Content-Transfer-Encoding: binary'); header('Content-Length: 20'); readfile("$file"); exit(); Quote Link to comment https://forums.phpfreaks.com/topic/157793-file_exists/#findComment-832322 Share on other sites More sharing options...
.josh Posted May 12, 2009 Share Posted May 12, 2009 Because you can't use readfile on some file from another server. Would you like it if I could just readfile anything on your server? Get all your server-side code, etc...? If you are wanting to send it through headers like that then you need to have your server access the file directly, through ftp for example. Quote Link to comment https://forums.phpfreaks.com/topic/157793-file_exists/#findComment-832324 Share on other sites More sharing options...
dreamwest Posted May 13, 2009 Author Share Posted May 13, 2009 Because you can't use readfile on some file from another server. Would you like it if I could just readfile anything on your server? Get all your server-side code, etc...? If you are wanting to send it through headers like that then you need to have your server access the file directly, through ftp for example. which ftp function connects to the file so the browser can download it. If i can do it without have to write the file to the main site but direct the file to the browser // define some variables $local_file = 'local.zip'; $server_file = 'server.zip'; // set up basic connection $conn_id = ftp_connect($ftp_server); // login with username and password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // try to download $server_file and save to $local_file if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) { //send the file to the browser instead of writing it to local server } else { echo "There was a problem\n"; } // close the connection ftp_close($conn_id); Quote Link to comment https://forums.phpfreaks.com/topic/157793-file_exists/#findComment-832905 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.