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.064 seconds

Awards for the best Joomla app. This product is gonna win an award for this amazing job. Cook Self Service is the the best application from all over the Joomla universe ! It brings Joomla to a professional level really advanced for developers. It is a real fun to develop with it. The ACL part and security checks implementation are just... so much hours saved. I can now concentrate myself more on the design part and the creative works. Thank you so much. Guys I offer you all my congratulation ! Keep up the works because Joomla is needing it to increase the quality of extensions availables on the JED. I also learned a lot because I can see how to code at the proper place and I found all my answers reading the forum.
lack_hanson (JED)
          

Get Started