Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 1.4.1

Bug #8102 Loading file extension and checking extension gives binary for ascii files
Submitted: 2006-07-02 18:09 UTC
From: roychri at php dot net Assigned: jorrit
Status: Closed Package: Net_FTP (version 1.3.2)
PHP Version: 4.3.11 OS: Mandrake Linux release 8.2 (Blue
Roadmaps: 1.3.3    
Subscription  


 [2006-07-02 18:09 UTC] roychri at php dot net (Christian Roy)
Description: ------------ I use getExtensionsFile() to load the ini file and then I use checkFileExtension() to determine the transfer mode based on the file extension. The function getExtensionsFile() is assigning the ini file parsed into a variable called _file_extension but everywhere in the FTP.php uses _file_extensions. I think that's a simple typo mistake in FTP.php. The function checkFileExtension() is using empty() to find out if that extension exists in the _file_extensions array but since the value is set to 0 for ascii, it thinks it's not in the in file and therefor return the default mode (binary). The function checkFileExtension() regular expression assumes there's only one dot in the filename and therefor cannot extract the correct extension from the filename when it contains multiple dots. To make it work, here are the changes I've made (patch format): --- /usr/local/lib/php/Net/FTP.php~ Sat Jul 1 10:03:22 2006 +++ /usr/local/lib/php/Net/FTP.php Sun Jul 2 10:52:28 2006 @@ -1427,7 +1427,7 @@ function checkFileExtension($filename) { - $pattern = "/\.(.*)$/"; + $pattern = "/\.([^\.]+)$/"; $has_extension = preg_match($pattern, $filename, $eregs); if (!$has_extension) { return $this->_mode; @@ -1435,7 +1435,7 @@ $ext = $eregs[1]; } - if (!empty($this->_file_extensions[$ext])) { + if (isset($this->_file_extensions[$ext])) { return $this->_file_extensions[$ext]; } @@ -1642,7 +1642,7 @@ return $this->raiseError("Extensions-file '$filename' is not readable", NET_FTP_ERR_EXTFILEREAD_FAILED); } - $this->_file_extension = @parse_ini_file($filename); + $this->_file_extensions = @parse_ini_file($filename); return true; } I hope this helps. Let me know if you need any more info. Thanks. -- christian roy Test script: --------------- $ftp =& new Net_FTP(); $loaded = $ftp->getExtensionsFile($path_to_ext_file."extensions.ini"); $type = $ftp->checkFileExtension("index.html"); print "index.html: type = $type\n"; $type = $ftp->checkFileExtension("www.google.com.html"); print "www.google.com.html: type = $type\n"; Expected result: ---------------- index.html: type = 0 www.google.com.html: type = 0 Actual result: -------------- index.html: type = 1 www.google.com.html: type = 1

Comments

 [2007-11-24 19:50 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!