Welcome, Guest
Username: Password: Remember me

TOPIC: Item cid in file renaming

Item cid in file renaming 25 Jan 2012 10:16 #1072

  • tr4ding
  • tr4ding's Avatar
  • Offline
  • Senior Member
  • Posts: 42
  • Karma: 1
Hy everybody!!! I'd like to thank you for your great component creator!!!!
It seems to be wonderful!!

About filename reaming......is there any possibility to rename filename with the ID of the record?....such as "1.jpg" and also to add a custom suffix, such as "1_low.jpg"?

I appreciate your interest!!! Thank you in advance :)
Last Edit: 25 Jan 2012 10:50 by admin.
The administrator has disabled public write access.

Item cid in file renaming 25 Jan 2012 10:30 #1073

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Hi and welcome to the community,


When you add a record, the file is uploaded before beiing saved in database.
So the ID does not exists when the file is renamed.

The solution is you can ask the user to first save the record, and then propose to upload an attached file.
(Do 2 forms with redirection, or limit the access of the input if ID doesn't exists)

Then, pass the id in the rename parameter.

It is not so difficult. I can help you if you have difficulties.
Coding is now a piece of cake
The administrator has disabled public write access.

Re: Item cid in file renaming 25 Jan 2012 10:55 #1076

  • tr4ding
  • tr4ding's Avatar
  • Offline
  • Senior Member
  • Posts: 42
  • Karma: 1
Thank you for your quick reply!!!

1. I don't know how to redirect a form to another :(

2. I don't know the exact syntax to pass the id in the rename parameter :(

I appreciate in advance your help :)
The administrator has disabled public write access.

Re: Item cid in file renaming 25 Jan 2012 16:11 #1087

  • tr4ding
  • tr4ding's Avatar
  • Offline
  • Senior Member
  • Posts: 42
  • Karma: 1
I solved the first issue (2 step forms) :)

Now i'm trying to solve the second one, about renaming file.......

In properties
>Rename file, i try this syntax: {ID}.{MIMEXT}.....but it doesn't work.....any clues?

Thank you so much :)
The administrator has disabled public write access.

Re: Item cid in file renaming 26 Jan 2012 15:53 #1104

  • tr4ding
  • tr4ding's Avatar
  • Offline
  • Senior Member
  • Posts: 42
  • Karma: 1
I looked around the "upload.php" file in "classes folder" and i noticed the function "renameFile()" in which are defined all markers......i have to find a way to implement the "CID MARKER" there in the code? (Eg.
$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
) Or is there any possibility to pass the cid value directly on the sandbox?

Thank you in advance!!!
The administrator has disabled public write access.

Re: Item cid in file renaming 26 Jan 2012 16:25 #1105

  • admin
  • admin's Avatar
  • Online
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 984
  • Karma: 140
Or is there any possibility to pass the cid value directly on the sandbox?
First, there is nothing to do with the sandboxes. You are currently coding inside your component.

Well, I give you the answer :

TODO :
controllers/{mycontroller}.php :

function save() AND function apply() :
//UPLOAD FILE : My File
if (!$this->_upload('my_file', &$post, array(
		'image/jpeg' => 'jpg,jpeg')
	, array(
		'overwrite' => 'yes',
		'rename' => '{BASE}.{EXT}',		// <-  HERE

	)))
	return;



replace with :
'rename' => (int) $cid[0] . '_{BASE}.{EXT}',

But you can change the patterns as you want ({BASE}, {ALIAS}, {EXT}, {BASEXT}, {RAND} ...


That solves ?


EDIT : I see you tried to add a {CID} pattern, wich is a nice idea, you can do it also...
So you can rewrite in the class file.

Add this code in the renameFile() function
//Cid when available
$cid = JRequest::getVar( 'cid', array(), 'post', 'array' );
if (count($cid))
	$this->parsePattern($pattern, "CID", (int)$cid[0]);

Not tested, but sould work.
Coding is now a piece of cake
Last Edit: 26 Jan 2012 16:32 by admin.
The administrator has disabled public write access.
Time to create page: 0.091 seconds

Get Started