Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

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

  • tr4ding
  • tr4ding's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 42
  • Thank you received: 0
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 :)

Please Log in or Create an account to join the conversation.

Last edit: by admin.

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986
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

Please Log in or Create an account to join the conversation.

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

  • tr4ding
  • tr4ding's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 42
  • Thank you received: 0
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 :)

Please Log in or Create an account to join the conversation.

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

  • tr4ding
  • tr4ding's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 42
  • Thank you received: 0
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 :)

Please Log in or Create an account to join the conversation.

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

  • tr4ding
  • tr4ding's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
  • Posts: 42
  • Thank you received: 0
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!!!

Please Log in or Create an account to join the conversation.

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

  • admin
  • admin's Avatar
  • Offline
  • Administrator
  • Administrator
  • Chef
  • Posts: 3711
  • Thank you received: 986

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

Please Log in or Create an account to join the conversation.

Last edit: by admin.
  • Page:
  • 1
Time to create page: 0.069 seconds

I jumped and started to work on a demo component... but 2 days later this demo component became the real component. I just showed today the end result to my customer and he turned to me and said... "this is more than I expected"... All of this is because Cook did cut about 70% of my work and provided me more ways to improve the usability of the component. The end result was 17 tables all related between than to generate a full dashboard for the travel agents. Thanks for Cook developers for such great tool. This component would not be possible to be done at short time with all the features in it
Griiettner (Forum)  

Get Started