Get&Store image id from file manager (image helper?)

Permalink 1 user found helpful
Hey!
How can I get the image id from filemanager (using a button that opens filemanager and lets you choose an image).

I tried Image and file helpers but I think they save the image, not its id.

Thank you a lot,
Martí

marticps
 
JohntheFish replied on at Permalink Reply
JohntheFish
In code:

http://www.concrete5.org/documentation/developers/files/files-and-f...
$f->getFileID();

Returns the ID of the file.
marticps replied on at Permalink Reply
marticps
Fatal Error: Call to a member function getFileID() on a non-object ...
C5LABS replied on at Permalink Reply
C5LABS
You need to grab the file object first.
Look into image block controller and the anwser his there.
Mainio replied on at Permalink Reply
Mainio
I think he asked how can he get the image selector. It's done like this:
$alh = Loader::helper('concrete/asset_library');
echo $alh->image('selector_html_id', 'your_image_field_name', t('Select an image'), $selectedFileObject);


And that will show up the selector. After adding that, the selected file id is available in $_POST['your_image_field_name'] in your controller.

Note that I have no idea where, why and how you're going to be using this, so this just shows the basics of this. E.g. if using that in a block or view controller, you should use $this->post('your_image_field_name') instead of the $_POST array.
marticps replied on at Permalink Reply
marticps
I have this done, but I think it returns the image, not the image ID.
Then, it's possible to get the image id from the image selector?

Thank you a lot :)

PS: Sorry for my english.
Mainio replied on at Permalink Best Answer Reply
Mainio
Yes, it returns the image id it saves in the hidden field named with the name you gave it. In the example above I gave that field name 'your_image_field_name'. So, after selecting the image the assets library will print out:
<input type="hidden" name="your_image_field_name" value="123" />


And the 123 there will be the id of the selected image. You can use that straight in your controller (whether it's a block or single page controller) when you post your form where that image selector is included.

Again, I really know nothing about the case in question, so no idea on how you're trying to use it.
marticps replied on at Permalink Reply
marticps
Oh yes it works now!!
(Its for showing a logo in my theme site).

It gets the path, but I have problems showing the image... It may be a css problem.
Thanks!
Mainio replied on at Permalink Reply
Mainio
Just copy the link from the image tag into your browser and see if it displays the image properly. If it does, then it's probably something with your CSS.

If it doesn't, then you probably are not getting the path right. You should be using:
$imageFile = File::getByID(123);
$relpath = $imageFile->getRelativePath();


And then in your view print the relpath into your image src.
marticps replied on at Permalink Reply
marticps
This worked perfect (When I loaded to my server it sayd Image URL:http://website.com/www.website.com/image)... so getRelativePath(); worked good.

Thank you :)