6

I am working with the image upload,i want to get the renamed images for save into my table.

    original file name : t h i r d_i_m_@g e(1).jpg
    renamed file name : 1435902886t_h_i_r_d_i_m__g_e_1_.jpg(in folder)

Code

    $uploader = new Varien_File_Uploader($field_name);
            $uploader->setAllowedExtensions($extension);
            $uploader->setAllowCreateFolders(true);
            $uploader->setAllowRenameFiles(true);
            $uploader->save($path,$fname);

When I print $uploader the result is:

    Varien_File_Uploader Object
    (
        [_file:protected] => Array
            (
                [name] => t h i r d_i_m_@g e(1).jpg
                [type] => image/jpeg
                [tmp_name] => /tmp/phpkUUDen
                [error] => 0
                [size] => 37994
            )

        [_fileMimeType:protected] => 
        [_uploadType:protected] => 0
        [_uploadedFileName:protected] => 1435904665t_h_i_r_d_i_m__g_e_1_.jpg
        [_uploadedFileDir:protected] => /home/vhosts/FederalLawyer/media/lawyer/news/image/
        [_allowCreateFolders:protected] => 1
        [_allowRenameFiles:protected] => 1
        [_enableFilesDispersion:protected] => 
        [_caseInsensitiveFilenames:protected] => 1
        [_dispretionPath:protected] => 
        [_fileExists:protected] => 1
        [_allowedExtensions:protected] => Array
            (
                [0] => jpg
                [1] => png
                [2] => gif
                [3] => jpeg
            )

        [_validateCallbacks:protected] => Array
            (
            )

        [_result:protected] => Array
            (
                [name] => t h i r d_i_m_@g e(1).jpg
                [type] => image/jpeg
                [tmp_name] => /tmp/phpkUUDen
                [error] => 0
                [size] => 37994
                [path] => /home/vhosts/FederalLawyer/media/lawyer/news/image/
                [file] => 1435904665t_h_i_r_d_i_m__g_e_1_.jpg
            )

    )

From this how can I get the renamed file name?

11

Using a simple function, you can use to get the image name after upload the image:

$uploader->getUploadedFileName();
0

Try to assign save value in one variable,,,like

$uploadresult=  $uploader->save($path,$fname);

And get save file like in this way

$saveFilename=    $uploadresult['file']

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.