0

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!

EDIT:

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']
            .$this->get_query_separator($this->options['script_url'])
            .'file='.rawurlencode($file_name);
            //  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()
        .$version_path.rawurlencode($file_name);
}

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

2
Contributors
1
Reply
14
Views
3 Years
Discussion Span
Last Post by LastMitch
0

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

@calebcook

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.