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