I'm using a plugin called jQuery file upload to upload images to a page. Currently it uploads with the original image name as the file name (IMG_1234). I need a specific format for the image name on the server (eg 1.123456.jpg)

I found this PHP code that works for changing the image name:

class CustomUploadHandler extends UploadHandler
    protected function trim_file_name($name, $type) {
        $name = time()."_1";
        $name = parent::trim_file_name($name, $type);
        return $name;

When I upload an image, it is named correctly, but the link for the image preview is undefined. This prevents me from deleting the image via the plugin.

The variable data.url is undefined... If I go back to the original code that doesn't rename the image, everything works fine.

Has anyone had any experience with this plugin that could help? Thanks!


I've found part of the problem at least...the function to return the download link (which is also used for deletion) is giving the original file name, not the updated one. I am really new to PHP classes, so I'm not sure where the variable originates and how to fix it. I'd really appreciate any help I can get!

Here's the PHP code for that function:

protected function get_download_url($file_name, $version = null, $direct = false) {
    if (!$direct && $this->options['download_via_php']) {
        $url = $this->options['script_url']
            //  The `$file_name` variable is the original image name (`IMG_1234`), and not the renamed file.  
        if ($version) {
            $url .= '&version='.rawurlencode($version);
        return $url.'&download=1';
    if (empty($version)) {
        $version_path = '';
    } else {
        $version_url = @$this->options['image_versions'][$version]['upload_url'];
        if ($version_url) {
            return $version_url.$this->get_user_path().rawurlencode($file_name);
        $version_path = rawurlencode($version).'/';
    return $this->options['upload_url'].$this->get_user_path()

EDIT 2: I think it has something to do with 'param_name' => 'files', in the options. Anyone know what that does?

Member Avatar

EDIT 2: I think it has something to do with 'param_name' => 'files', in the options. Anyone know what that does?


How did you solve your issue? Can you at least mention how you did it?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.