formfields.com Forum Index formfields.com
FORMfields Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Bug in the v2.0 UploadFields - FF_UPLOAD_DIR_URL

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    formfields.com Forum Index -> FF 2.X - Bug Reports
View previous topic :: View next topic  
Author Message
getresults



Joined: 12 Oct 2005
Posts: 16

PostPosted: Sat Dec 24, 2005 1:00 am    Post subject: Bug in the v2.0 UploadFields - FF_UPLOAD_DIR_URL Reply with quote

When specifying an upload directory in UploadFields() the uploaded file is stored to the correct location.

However, the link to the file stored in the database is incorrect. It is always hardcoded to FF_UPLOAD_DIR_URL rather than to the correct URL based on $uploadDir.

So the file is uploaded to the correct directoy just fine, but the link from the database claims it is always stored in the FORMfields/uploads directory.

Could we have a fix for this please?

Thank you!

P.S. - I'd also like to know how I can display the filename returned from the database as a URL so that I can click on the link for the file and have the browser download it from the server.

Have an awesome Christmas! Can't wait for FORMgen V2!
Back to top
View user's profile Send private message
formfields



Joined: 01 Aug 2005
Posts: 465

PostPosted: Wed Dec 28, 2005 4:38 pm    Post subject: Reply with quote

Thank you for your submission. Here is a better implementation of the UploadField that allows you to specify a upload directory URL. Please open your /FORMfields/FORMfields.php and replace the exisiting UploadField code with:
Code:

   class UploadField extends FileField {

      var $maxFileSize;
      var $fileProperties; // name, type, size, tmp_name, error in the $_FILES array
      var $uploadDir;
      var $uploadDirUrl;
      var $uploadedFile;

      function __construct($name, $label, $required, $maxFileSize, $uploadDir=FF_UPLOAD_DIR, $uploadDirUrl=FF_UPLOAD_DIR_URL) {
         parent::__construct($name, $label, $required);
         $this->maxFileSize = $maxFileSize;
         $this->uploadDir = $uploadDir;
         $this->uploadDirUrl = $uploadDirUrl;
      }
      
      // Deprecated on 2005.12.19
      function UploadField($name, $label, $required, $maxFileSize, $uploadDir=FF_UPLOAD_DIR, $uploadDirUrl=FF_UPLOAD_DIR_URL) {
         $this->__construct($name, $label, $required, $maxFileSize, $uploadDir, $uploadDirUrl);
      }

      function getEditableFieldTag() {
         return "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" . $this->maxFileSize . "\" />"
            . parent::getEditableFieldTag();
      }
      
      function getParameter() {
         parent::getParameter();
         $this->fileProperties = FORMfield::getOrNull($this->getName(), $_FILES);
         if ($this->fileProperties != null)
            $this->setValue($this->fileProperties["name"]);
      }
      
      function isValid() {
         if (!parent::isValid())
            return false;
         if ($this->getValue() == null)
            return true;
         switch ($this->fileProperties["error"]) {
            
            case UPLOAD_ERR_INI_SIZE:
               $this->setError("is too large!");
               break;
            
            case UPLOAD_ERR_FORM_SIZE:
               $this->setError("must be less than " . $this->maxFileSize . " bytes!");
               break;
            
            case UPLOAD_ERR_PARTIAL:
               $this->setError("upload failed! Please try again.");
               break;
            
            case UPLOAD_ERR_NO_TMP_DIR:
               $this->setError("missing a temporary folder! Please contact administrator.");
               break;
               
            case UPLOAD_ERR_NO_FILE:
            case UPLOAD_ERR_OK:
               if ($this->uploadDir) {
                  $pathParts = pathinfo($this->getValue());
                  // Note: On some PHP installations basename doesn't work with back slashes
                  $filename = str_replace(" ", "", basename(str_replace("\\", "/", stripslashes($this->getValue())), "." . $pathParts["extension"]) . "-" . time() . "." . $pathParts["extension"]);
                  $savedFile = $this->uploadDir . "/" . $filename;
                  $this->uploadedFile = $this->uploadDirUrl . "/" . $filename;
                  rename($this->fileProperties["tmp_name"], $savedFile);
                  chmod($savedFile, 0604); // Make the uploaded file readable
               }
               return true;
               //break;
         }
         return false;
      }
      
      function moveUploadedFile($destination) {
         move_uploaded_file($this->fileProperties["tmp_name"], $destination);
      }
      
      function getRawDbValue() {
         return $this->uploadedFile;
      }
      
      function getDisplayValue() {
         return $this->uploadedFile;
      }

   }
Back to top
View user's profile Send private message
formfields



Joined: 01 Aug 2005
Posts: 465

PostPosted: Wed Dec 28, 2005 4:40 pm    Post subject: Reply with quote

You can use the method outlined at http://www.formfields.com/phpBB2/viewtopic.php?t=118 to display a hyperlink to your uploaded files.
Back to top
View user's profile Send private message
Guest






PostPosted: Thu Dec 29, 2005 9:23 am    Post subject: Reply with quote

formfields wrote:
Thank you for your submission. Here is a better implementation of the UploadField that allows you to specify a upload directory URL. Please open your /FORMfields/FORMfields.php and replace the exisiting UploadField code with:


Hi!

Thank you for the updated Upload Field.

There's one problem with the new function - it works great on PHP 5.0 but breaks on PHP Version 4.3.10. It seems that __construct is a version 5 feature?

Are you able to give us the updated function in a format compatible with earlier versions of PHP? Thank you - I really apprecaite it! Smile

Looks like I'm going to have to change my web hosting service at some point. I use www.neureal.com which is an absolutely brilliant company but they are still using PHP 4.3.10 and Mysql 3.4.something.

Thanks again!
Back to top
formfields



Joined: 01 Aug 2005
Posts: 465

PostPosted: Tue Jan 03, 2006 12:14 am    Post subject: Reply with quote

Actually, this function should be compatible with both PHP 4 and PHP 5. What error message do you receive in PHP 4?
Back to top
View user's profile Send private message
Guest






PostPosted: Wed Jan 04, 2006 11:45 pm    Post subject: Reply with quote

formfields wrote:
Actually, this function should be compatible with both PHP 4 and PHP 5. What error message do you receive in PHP 4?


Sure thing:

Code:
Fatal error: Call to undefined function: __construct() in /local/home/foo/html/FORMfields/FORMfields.php on line 2280


That particular server uses PHP Version 4.3.10

See the following thread for helpful informaton - "Php 4.4.1 constructor Vs. Php 5.0 constructor":

http://www.issociate.de/board/post/282148/php_4.4.1_constructor_Vs._Php_5.0_constructor.html
Back to top
formfields



Joined: 01 Aug 2005
Posts: 465

PostPosted: Sat Jan 07, 2006 7:00 pm    Post subject: Reply with quote

Thank you for you report. Unfortunately, we are unable to duplicate this error. Is there any chance that you could use the Contact Us link at http://www.formfields.com/contactUs.php to send us a link to your form that is causing this problem?
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    formfields.com Forum Index -> FF 2.X - Bug Reports All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group