Jump to content

file_exists()


dreamwest

Recommended Posts

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();
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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();

Link to comment
Share on other sites

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);

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.