File type upload

edited December 2010 in Modules
Hi,

I coudn't find how to upload pdf file, I have table
CREATE TABLE IF NOT EXISTS `special_offers` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'The name of the project', `slug` varchar(255) COLLATE utf8_unicode_ci NOT NULL COMMENT 'If left blank, one will automatically be generated for you', `description` text COLLATE utf8_unicode_ci NOT NULL, `launch_date` date DEFAULT NULL, `image` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `pdf` varchar(100) COLLATE utf8_unicode_ci NOT NULL, `precedence` int(11) NOT NULL DEFAULT '999' COMMENT 'The higher the number, the more important', `published` enum('yes','no') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'yes', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2 ;
Want to upload pdf and save file name in pdf, added these options to field pdf
$fields['pdf'] = array('label' => 'PDF file', 'type' => 'file', 'upload_path' =>assets_server_path('special_offers', 'pdf'), 'overwrite' => TRUE);
I have Image and pdf upload, so where can i set that when uploading from pdf, to allow pdf extension,
now it gives error "The filetype you are attempting to upload is not allowed."

Comments

  • edited 8:36PM
    okay, needed to better study user guide
    http://www.getfuelcms.com/user_guide/libraries/form_builder
  • edited January 2011
    Similar issue, I'm wanting to upload mp4's and ogg's.

    I'm trying to do it in a module so I have something in a projects_model.php

    was hoping that 'accept' => 'mp4' would do it, but no go.

    in my form_fields function:
    $fields['video_mp4_upload'] = array('type' => 'file', 'accept' => 'mp4', 'upload_path' => assets_server_path('videos'), 'overwrite' => TRUE); $fields['video_mp4_upload']['order'] = 6; $fields['video_ogg_upload'] = array('type' => 'file', 'accept' => 'ogg', 'upload_path' => assets_server_path('videos'), 'overwrite' => TRUE); $fields['video_ogg_upload']['order'] = 8;
    It does work with images, but not video formats.

    Thanks,
    Dustin
  • edited 8:36PM
    Hey Dustin,

    I'm looking into this. Questions for you though:
    1. When you say 'no go' do you mean that you are getting an error on upload, or that your browser won't let you select the mp4 file to upload?
    2. What browser are you using?
  • edited 8:36PM
    Also, did you try configuring the file types that are accepted for the folder you are uploading to? There is a $config['editable_asset_filetypes'] you can set in your fuel/application/config/MY_fuel.php

    http://www.getfuelcms.com/user_guide/general/configuration
  • edited January 2011
    1. "no go" isn't quite the best tech term huh :)
    no error is shown.
    the browser lets me select the image and it shows the file that i'm going to upload. It's when i hit save that it fails with no notice as to why.

    I'm using the http://www.getfuelcms.com/demo/showcase example and added the uploads for my videos to the module.


    so i'm wondering whats the trigger that tells it that its an image vs any other file. because I can upload a jpg and it goes into the correct directory that i'm wishing. Is there something in the input that I can change it to "media" rather than an "image".

    I see that it's rendering out the image accept data
    so where is 'images', 'pdf',and 'media' used


    <input type="file" name="video_mp4_upload" id="video_mp4_upload" value="" accept="gif|jpg|png">

    I added the mp4 to it
    $config['editable_asset_filetypes'] = array('images' => 'jpg|jpeg|jpe|gif|png', 'pdf' => 'pdf', 'media' => 'jpg|jpeg|jpe|png|gif|mov|mp3|aiff|pdf|mp4|ogv');


    double checked the size

    $config['assets_upload_max_size'] = '10000'; //was 1000

    2. testing mostly in firefox 3.6 & chrome 8.0
  • edited 8:36PM
    What if you change the upload_path field property to 'media' instead of 'videos' (and make sure media is writable)?
  • edited March 2011
    So I had the same problem this morning. Turns out it wasn't working for 2 reasons. After the following changes I got it to work.

    1. You are likely missing the mime for mp4 in your mime.php config file. Add this to the array:
    'mp4' => 'video/mp4',

    2. FuelCMS is trying to sanitize the file as an image and check for xss. One of these 2 is failing against the mp4 file. As a quick fix, I'm skipping the check for any media file.
    [line 1286] /fuel/modules/fuel/controllers/module.php if ($this->sanitize_images AND xss_clean($tmp_file, TRUE) === FALSE AND $asset_dir != 'media')

    UPDATE: Adding "sanitize_images" => FALSE to the form field fixes the second problem.
  • edited 8:36PM
    I'd recommend setting the "sanitize_images" => FALSE in your modules configuration:
    http://www.getfuelcms.com/user_guide/modules/simple
  • edited 8:36PM
    That is a much better solution. :)

    Thanks
  • edited 8:36PM
    The problem was for the following line in Upload.php (fuel/codeigniter/libraries):

    if (in_array($this->file_type, $mime, TRUE))
    {
    return TRUE;
    }

    When I run, the value of $this->file_type was 'application/octet-stream', and for example the $mime variable have all the mimes referent to the extension (in my case all mime types of zip extension).

    To get a factible solution, just add the 'application/octet-stream' to the array of the mime type, on the file 'fuel/application/config/mimes.php', just like this:

    'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed', 'application/octet-stream')

    I hope this works for anyone. Works for me!.
  • edited 8:36PM
    I'm having problems with this too.

    I created a folder "ebooks" and I'm trying to upload a PDF and Excel file to the folder and it is still giving me this error: "The filetype you are attempting to upload is not allowed."


    $config['editable_asset_filetypes'] =
    array(
    'images' => 'jpg|jpeg|jpe|gif|png',
    'pdf' => 'pdf',
    'Excel' => 'xls',
    'media' => 'jpg|jpeg|jpe|png|gif|mov|mp3|aiff'
    );
  • edited 8:36PM
    Does it work if you change "Excel" to "ebooks" in the array key? The key is the folder name and the value is the types of files that it should accept that maps to the fuel/application/config/mimes.php file.
  • edited 8:36PM
    No. It's still not working... I hope I can get this fixed b/c I LOVE this CMS.
  • edited 8:36PM
    Is this with the 1.0 beta branch or 0.93? Also, it could be that the CodeIgniter mime type mapping may need to be modified. There is a "mimes_types" method on the CI Upload class that you can debug to see if the mime being returned by the server matches one that is in the mime config.
  • edited 8:36PM
    How do I figure out which version I have?
  • edited 8:36PM
    You can echo out the FUEL_VERSION constant somewhere or look in the fuel/modules/fuel/config/fuel_constants.php file at the top.
  • edited 8:36PM
    I'm using 0.93... It seems like the initial problem is the javascript alert that says "You cannot select a .pdf file".. How do I debug that???
  • edited 8:36PM
    Is this while attempting to upload from the Assets module or from attempting to upload from within your own module? Also, if you are attempting to upload to a PDF to that folder, you'll need to specify that file type extension as well:
    'ebooks' => 'xls|pdf',
  • edited 8:36PM
    This is from the Assets Module...

    This is exactly what I have:

    $config['editable_asset_filetypes'] =
    array(
    'images' => 'jpg|jpeg|jpe|gif|png',
    'pdf' => 'pdf',
    'ebooks' => 'xls|pdf',
    'media' => 'jpg|jpeg|jpe|png|gif|mov|mp3|aiff'
    );
  • edited 8:36PM
    Try adding pdf and xls to the 'media' folder. The media one is used as the catch all for all asset types in 0.93.
    'media' => 'jpg|jpeg|jpe|png|gif|mov|mp3|aiff|pdf|css|pdf|xls'
  • edited 8:36PM
    So, I've found the problem.

    LIKE futbolsalso15 said it's in the codeigniter..

    Fuel 0.93
    /fuel/codeigniter/libraries/upload.php file..

    line 199.. echo $_FILES[$field]['type'] . "
    \n";

    I get "image/pdf" as a file type.... odd...

    I also found an article that says each browser has a different mime type for uploading PDF.. I'm using FireFox 22
Sign In or Register to comment.