Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Change File Name and Path #1128

Closed
techzombie opened this issue Mar 26, 2012 · 6 comments
Closed

Change File Name and Path #1128

techzombie opened this issue Mar 26, 2012 · 6 comments

Comments

@techzombie
Copy link

Hi,

I just want to specify a new file name for the uploaded files. I can pass this on the same page I have the form.

For example using their sesionid via php.
23541342534534534534.mp instead of "in da club.mp"

How can I pass this custom file name to the script?

Bonus: How can I change the upload directory from the html form page ?

@tijmenamsing
Copy link

In case you are using php you can change the filename and upload directory in server/php/upload.class.php

upload dir: In the constructor function change the options: upload_dir and upload_url

filename:I would make a hidden field in the form which passes the session_id. Then in upload.class.php / function trim_file_name you can set the passed session id as filename: $file_name = $_POST['session_id'];

@techzombie
Copy link
Author

excellent answer, got it working well.

thank u

they should put this into the FAW's since i am sure this is the 1. or 2. question for most

@blueimp blueimp closed this as completed Sep 6, 2012
@tmcnicholl
Copy link

Hi, I have tried this to try and set the file name, but it just seems to append the existing filename onto what you set. For example, I changed the options in the constructor to:

'upload_dir' => dirname($_SERVER['SCRIPT_FILENAME']).'../example/inv/myfile.pdf',
'upload_url' => $this->get_full_url().'../example/inv/myfile.pdf',

...where I want the file to be named 'myfile.php', but it just uploads the files as:

...../example/inv/myfile.pdftestpdf.pdf

The file I uploaded was named 'testpdf.pdf'. Do you know how you can make it write over the existing file name and ensure it is saved as the one set in the constructor?

Thanks

@butch2k
Copy link

butch2k commented Nov 15, 2012

change ME']).'../exa to ME']).'/../exa

On Thu, Nov 15, 2012 at 2:20 PM, tmcnicholl notifications@github.comwrote:

Hi, I have tried this to try and set the file name, but it just seems to
append the existing filename onto what you set. For example, I changed the
options in the constructor to:

'upload_dir' =>
dirname($_SERVER['SCRIPT_FILENAME']).'../example/inv/myfile.pdf',
'upload_url' => $this->get_full_url().'../example/inv/myfile.pdf',

...where I want the file to be named 'myfile.php', but it just uploads the
files as:

...../example/inv/myfile.pdftestpdf.pdf

The file I uploaded was named 'testpdf.pdf'. Do you know how you can make
it write over the existing file name and ensure it is saved as the one set
in the constructor?

Thanks


Reply to this email directly or view it on GitHubhttps://github.com//issues/1128#issuecomment-10408185.

@ionurboz
Copy link

This is a real problem :/ I'll test Uniqid()

@almuete
Copy link

almuete commented Mar 9, 2014

protected function trim_file_name($file_path, $name, $size, $type, $error,
$index, $content_range) {

....

end of line
/* start added line /
$split_ext = explode('.',$name);
$ext = end($split_ext);
$name = sha1(time()).'.'.$ext;
/
end added line */

    return $name;
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants