Page 1 of 1

Strange behavior due to different uploaded file types

PostPosted: Wed Nov 25, 2009 9:24 pm
by conkhikho
I don't know how to concisely explain the problem, so the subject is probably unclear.

What I want to achieve is: The user can upload a file (either images with extensions jpg or bmp, or video clips with extension f4v or flv), and upon uploading, the file is processed and organized to its appropriate folder (not its default).

How I am doing this: I have a widget:type = file for a field called AFilename (in which the user can browse to the file). This field is eventually set to hold the file name alone with no extension. Temporary folder to store the file is defined in savepath and url. There is another field called 'type' for the user to indicate whether this is an image or a video. Here's the rough code

Code: Select all
<php>

class tables_assets {
     
     function beforeInsert(&$record){

          if ( $record->valueChanged('AFilename') ){

            $fieldDef =& $record->_table->getField('AFilename');
            
            // get extension based on .
            // get filename based on extension
            $filen = $record->val('AFilename');
            $filename = basename($filen); // filename.ext
            $extension = end(explode('.', $filename)); // ext
            $filename = basename($filen, ".".$extension); // filename
      
            $newFilename = $filename;

            if ($record->val('type') == 1){ // image
               // build the new file path and rename the image to that file path
               .....
            }
            else if ($record->val('type') == 2) { // video
               // build the new file path and rename the video to that file path
               .......
            }

            // 2. set the file name
            $record->setValue('AFilename', $newFilename);
          }
         
     }

}

?>


Now the problem is: It works fine for type 1 (image), but when i try uploading a type 2 file (video), xataface returns an error saying
"Errors
* Some errors occurred while processing this form:
o AFilename is a required field.
"

I really have no clue why this happens. Any suggestion is greatly appreciated. Thanks a lot folks.

Tim

PostPosted: Tue Dec 01, 2009 1:47 pm
by shannah
My guess is this is related to file size. Check your PHP settings for max upload size and max post size. If you upload a file that exceeds this size then the file won't be passed through and your "required" validator for the field will fail.

PostPosted: Wed Dec 02, 2009 12:11 pm
by conkhikho
Thank you very much Steve. Yeah, it's the file size limit problem... Once I set a higher limit, the problem is gone.