简体   繁体   中英

Check filesize through PHP on FTP server for file without an extension?

I'm trying to create a progress bar for a file being FTP using PHP. To start this, I need to find the file size of the item to be downloaded. The issue is that the file does not have an extension - it's simply "map". When using PHP's filesize() I get thrown some errors. My assumption is that it needs an extension specified (tested with extension and it works fine). What I would like to do in the end:

  1. Determine the file size of the remote file
  2. Start the FTP download
  3. Send an AJAX call to the local file to determine its file size
  4. Increase displayed progress bar with JS

My assumption is that this should work - that is if I can determine the initial size of the file without having a defined extension.

Is this possible, or is there another method that may prove easier?

If I understand correctly what you are trying to do (download a remote file from an FTP server), I don't think you can use filesize function, as it only deals with local files. To get a file size of a remote file on an FTP server, you need to use something like this:

$file = '/remote/path/map';
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
$res = ftp_size($conn_id, $file);

if ($res != -1) {
    echo "size of $file is $res bytes";
} else {
    echo "couldn't get the size";
}
ftp_close($conn_id);

Have a look at ftp_size function .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM