• 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!

TOPIC: How To Change File Upload Name

How To Change File Upload Name 9 years 8 months ago #28371

I want to change the file name, such as the specific time when they submit(Y-M-D-H-I-S).

Thanks in advance.
The administrator has disabled public write access.

How To Change File Upload Name 9 years 8 months ago #28373

  • cosmin.cristea
  • cosmin.cristea's Avatar
  • OFFLINE
  • Platinum Boarder
  • Posts: 756
  • Thank you received: 144
Changing the name of the uploaded file is not possible, however you can use the "File Prefix" (Edit field > Attributes > File Prefix) functionality to dynamically change it's prefix with PHP

For example, you can use this code :
//<code>
return date("Y_m_d H_i_s")." ";
//</code>

and it will return the date as a prefix , e.g. :

2014_08_04 11_13_04 uploadedfile.zip

More information on this can be found here:

http://www.rsjoomla.com/support/documentation/view-article/831-file-upload.html
My help is not official customer support. To receive your support, submit a ticket by clicking here
Last Edit: 9 years 8 months ago by cosmin.cristea.
The administrator has disabled public write access.

How To Change File Upload Name 9 years 8 months ago #28377

I have used this example code, thanks a lot.

But,

If the file name is Korean, Japanese or Chinese, then the name garbled.

If the file name is a combination of English and other languages, the prompt box will be displayed "Warning: Failed to move file!"

I found a components ,it can change the name of the file.
if ( JSNUniformUpload::canUpload( $file, $err, $fieldSettings ) ) {
	$nameFile = strtolower( date( 'YmdHiS' ) . $fieldIdentifier . '_' . rand( 100000000, 9999999999999 ) . '_' . $file[ 'name' ] );
	$filepath = JPath::clean( $folderRoot . '/' . $post[ 'form_id' ] . '/' . $nameFile );

and the result is the url like "images/uploads/1/201408041848th7_405815175_1.jpg"

How could I achieve this effect。

Looking forward to your reply.
The administrator has disabled public write access.

How To Change File Upload Name 9 years 5 months ago #29259

  • modernmagic
  • modernmagic's Avatar
  • OFFLINE
  • Junior Boarder
  • Posts: 32
  • Thank you received: 2
Is it possible to add the {NAME:value} and the "File Upload" Form Field name to the uploaded file's name?
The administrator has disabled public write access.

How To Change File Upload Name 9 years 5 months ago #29360

  • patrick.jackson
  • patrick.jackson's Avatar
  • OFFLINE
  • Junior Boarder
  • Joomla Consultant, Melbourne Australia
  • Posts: 21
  • Thank you received: 4
modernmagic,

As was mentioned, instructions are here
www.rsjoomla.com/support/documentation/v...831-file-upload.html

So for your purpose, you would put the following in the File Prefix:
//<code>
return $_POST['form']['NAME']."_FILE-UPLOAD-FIELD_";
//</code>

This would give it a filename that has the value submitted and the _FILE-UPLOAD-FIELD_ value before the original filename that was uploaded.
//<code>
return $_POST['form']['lastname']."_".$_POST['form']['firstname']."_";
//</code>

This second example would add the submitted lastname and firstname values so the filename would look like lastname_firstname_originalfilename.ext

Hope that helps.

(found this thread while trying to clear the original filename off as part of the upload, but appears that can't be done at the moment)
Joomla Consultant & Hosting Provider
Melbourne Australia
The administrator has disabled public write access.
The following user(s) said Thank You: peter s.

How To Change File Upload Name 9 years 5 months ago #29361

  • patrick.jackson
  • patrick.jackson's Avatar
  • OFFLINE
  • Junior Boarder
  • Joomla Consultant, Melbourne Australia
  • Posts: 21
  • Thank you received: 4
feysherry,

What you're trying to do is rename the file on the fly to get around the other language character sets.

Currently I believe that can't be done due to the RSForm upload not doing a complete rename (or not that I've worked out as yet).

I've done it with Chronoforms for another project, but am keen to do it with RSForms so will post back here if/when I find a solution.
Joomla Consultant & Hosting Provider
Melbourne Australia
The administrator has disabled public write access.

How To Change File Upload Name 8 years 11 months ago #31280

  • aroun
  • aroun's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
I have been able to get this to work, but only by editing a core file. The edit is nothing too crazy as it just uses the str_replace() method to replace the spaces in the file names with a -. What I did isn't exactly related to what feysherry was looking for, but the name of the file can still be changed to whatever. The file to edit would be /administrator/components/com_rsform/helpers/rsform.php around line 2717. Just look for the following code...

$file = $realpath.$prefix.$files['form']['name'][$fieldName];

and change to....

$file = str_replace(" ", "-", $realpath.$prefix.$files['form']['name'][$fieldName]);

You can also replace other odd characters, commas, etc using preg_replace() and a regular expression. The only down side to this is having to edit a core file so if this is used just don't forget to change it again after an update to RSForm Pro. Also don't forget that if there are already files that have been uploaded you'll need to update the names in the database as well as on the server. I can post how to do that if anyone is interested...
Last Edit: 8 years 11 months ago by aroun. Reason: Added additional info
The administrator has disabled public write access.

How To Change File Upload Name 7 years 5 months ago #36034

  • patrick.jackson
  • patrick.jackson's Avatar
  • OFFLINE
  • Junior Boarder
  • Joomla Consultant, Melbourne Australia
  • Posts: 21
  • Thank you received: 4
aroun,

Nice solution - to avoid having to update the core on it, I've just requested it as a feature moving forward. I've just encountered it as an issue once again (something I only had to do every two years).

I've just submitted a request to get it looked at being added to the component moving forward.


Discuss the feature request more specifically here:
www.rsjoomla.com/forum/37-rsform-pro/280...on-upload.html#36033


Patrick
Joomla Consultant & Hosting Provider
Melbourne Australia
Last Edit: 7 years 5 months ago by patrick.jackson.
The administrator has disabled public write access.

How To Change File Upload Name 5 years 1 month ago #38957

  • s.span
  • s.span's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
patrick.jackson wrote:
modernmagic,

As was mentioned, instructions are here
www.rsjoomla.com/support/documentation/v...831-file-upload.html

So for your purpose, you would put the following in the File Prefix:
//<code>
return $_POST['form']['NAME']."_FILE-UPLOAD-FIELD_";
//</code>

This would give it a filename that has the value submitted and the _FILE-UPLOAD-FIELD_ value before the original filename that was uploaded.
//<code>
return $_POST['form']['lastname']."_".$_POST['form']['firstname']."_";
//</code>

This second example would add the submitted lastname and firstname values so the filename would look like lastname_firstname_originalfilename.ext

Hope that helps.

(found this thread while trying to clear the original filename off as part of the upload, but appears that can't be done at the moment)
I tried using this with a drop down box, but get 'Array' returned as the value instead of the actual value from the drop down. I have googled for some time now, but cannot get it to work. Can anyone help me?
The current code is:
//<code>
return $_POST['form']['Date']."_".$_POST['form']['Apparatus']."_";
//</code>
where the Apparatus is the single select drop down menu item on the form.
The administrator has disabled public write access.

How To Change File Upload Name 5 years 1 month ago #38962

  • adrianp
  • adrianp's Avatar
  • OFFLINE
  • RSJoomla! Official Staff
  • Posts: 631
  • Thank you received: 146
@s.span the dropdown is an array, thus receiving the Array string. You'll have to signify the actual submitted selection, for example (assuming Apparatus is your dropdown):
$_POST['form']['Apparatus'][0]
This is not official customer support. To receive your support, submit a support ticket here.
The administrator has disabled public write access.
The following user(s) said Thank You: s.span

How To Change File Upload Name 5 years 1 month ago #38966

  • s.span
  • s.span's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 8
This worked! Thank you so much.
The administrator has disabled public write access.

How To Change File Upload Name 2 years 9 months ago #41384

In PHP scripts add:

$ext=explode('.',$_FILES);
$ext=$ext[1];
$filename = 'name_of_your_file';
$_FILES=$filename . '.' . $ext;
The administrator has disabled public write access.
  • 1

Read this first!

We do not monitor these forums. The forum is provided to exchange information and experience with other users ONLY. Forum responses are not guaranteed.

However, please submit a ticket if you have an active subscription and wish to receive support. Our ticketing system is the only way of getting in touch with RSJoomla! and receiving the official RSJoomla! Customer Support.

For more information, the Support Policy is located here.

Thank you!