KnpLabs / Gaufrette

PHP library that provides a filesystem abstraction layer − will be a feast for your files!
http://knplabs.github.io/Gaufrette
MIT License
2.47k stars 354 forks source link

FTP exists = false, read gets the file #319

Open lsv opened 9 years ago

lsv commented 9 years ago
$url = '152/152.pdf';

$this->filesystem = @gaufrette.invoice_filesystem // Symfony service
$this->filesystem->has($url); // FALSE
$this->filesystem->getAdapter()->exists($url); // FALSE
$this->filesystem->getAdapter()->read($url); // Gives me the PDF file
$this->filesystem->get($url); // Exception FileNotFound

The file (when I use the read, gets saved nicely in my invoice_local) and the content is correct But why does the has, exists and get gives me false/exception ?

I also tried add the 152 directory to directory to the FTP configuration, but still the same.

knp_gaufrette:
  adapters:
    invoice_ftp:
      ftp:
        host: ftp.localhost
        directory: /upload

    invoice_local:
      safe_local:
        directory: "%kernel.cache_dir%/invoices"

    invoice_cache:
      cache:
        source: invoice_ftp
        cache: invoice_local
        ttl: 7200
  filesystems:
    invoice:
      adapter: invoice_cache
lsv commented 9 years ago

Found the problem, its because the PDF file was saved with capital letters.

And its hosted on a microsoft server, thats why the preg_match says the file as not found, but the read function reads direct from the FTP server (PHP ftp functions) and therefor it could read the file, but not "get" the file.

Maybe this should be mentioned in the documentation?

jtopenpetition commented 1 month ago

exists doesn't exactly check for the existence of the file, instead it fetches the directory listing and looks for the filename in there. Apparently some ftp servers do not provide all files in a directory listing with a huge amount of files. ftp_rawlist($conn, $filename) returns the filename, ftp_rawlist($conn, $prefixOfFilename) does not.