Uploads - Get and save filename

Uploads - Get and save filename

mm789000mm789000 Posts: 25Questions: 2Answers: 0

Hi,
I use uploads in my scripts ( Server side ).
But i want to store in my hown table ( not files table ) the filename , i don't want file_id.

Field::inst( 'logo' )
->setFormatter( Format::ifEmpty( null ) )
->upload( Upload::inst( $_SERVER['DOCUMENT_ROOT'].'/uploads/ID.EXTN' )
->db( 'files', 'id', array(
'filename' => Upload::DB_FILE_NAME,
'filesize' => Upload::DB_FILE_SIZE,
'web_path' => Upload::DB_WEB_PATH,
'system_path' => Upload::DB_SYSTEM_PATH
) )
->validator( Validate::fileSize( 500000, 'Files must be smaller that 500K' ) )
->validator( Validate::fileExtensions( array( 'png', 'jpg', 'jpeg', 'gif' ), "Please upload an image" ) )
),

In fact i get the file_id to my logo field, but i only need filename.
How can i do that ?

Regards

Replies

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    This thread should help, it's asking the same thing.

    Cheers,

    Colin

  • mm789000mm789000 Posts: 25Questions: 2Answers: 0

    Thanks for your reply.
    But is there a way to use upload but without saving file informations into the database,
    and only populate my field with the name of the file ?

    Regards,
    Mike

  • mm789000mm789000 Posts: 25Questions: 2Answers: 0

    Hi,
    i mean, in server-side, save the filename in my own table field.
    Regards.

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    Yes you can - the documentation for a custom upload action is here. You'd move the file (or copy it or whatever it is you need to do) and then return the reference you want to use to the file (file name?). You don't need to specify a db method call.

    You need to be really careful when storing by file name. Consider what would happen if user B uploaded a file which has the same name as a file uploaded by user B. Overwrite and lose the original, reject it or change the naming?

    Allan

  • mm789000mm789000 Posts: 25Questions: 2Answers: 0

    Hi,
    Thanks. There is no problem with the name, because all our files are rename with a specific name ( key_name + id ) , So never the same name.

    Mike

This discussion has been closed.