Replacing Image Path for Display

Talk about Image/File fields (uploading, problems etc.)

Moderator: alexandrleonenko

erichhaubrich
Newbie
Newbie
Posts: 4
Joined: Apr 27th, '10, 19:44

Replacing Image Path for Display

Postby erichhaubrich » Aug 21st, '10, 04:09

I'm trying to display images whose path is stored in my DB like this:

Code: Select all

/home/ACCOUNT/public_html/MYWEBSITE.com/components/com_facileforms/uploads/the-image.jpg


The image URL that Datagrid puts in the image tag is:

Code: Select all

http://MYWEBSITE.com/home/ACCOUNT/public_html/MYWEBSITE.com/components/com_facileforms/uploads/the-image.jpg


The actual image URL is:

Code: Select all

http://MYWEBSITE.com/components/com_facileforms/uploads/the-image.jpg


This is the current output in Edit Mode:

Code: Select all

<img src="/home/ACCOUNT/public_html/MYWEBSITE.com/components/com_facileforms/uploads/the-image.jpg" height="90px" width="120px" title="/home/ACCOUNT/public_html/MYWEBSITE.com/components/com_facileforms/uploads/the-image.jpg (265 x 140 - 17.88 Kb)" alt="/home/ACCOUNT/public_html/MYWEBSITE.com/components/com_facileforms/the-image.jpg">


Datagrid is finding the image and reading its size, etc. but it will not display in a browser.

This is how I have the field coded:

Code: Select all

// Image 1
"image1"=>array("header"=>"Main Image", "type"=>"image", "req_type"=>"st", "width"=>"220px", "title"=>"", "readonly"=>"false", "maxlength"=>"-1", "default"=>"", "unique"=>"false", "unique_condition"=>"", "visible"=>"true", "on_js_event"=>"", "target_path"=>"", "max_file_size"=>"2048K", "image_width"=>"120px", "image_height"=>"90px", "resize_image"=>"false", "resize_width"=>"", "resize_height"=>"", "magnify"=>"false", "magnify_type"=>"lightbox", "magnify_power"=>"2", "file_name"=>"", "host"=>"local"),


In a different version I tried using some other string variables to replace the string:

Code: Select all

// IMAGE PATH REPLACE
$pathStrip = "/home/ACCOUNT/public_html/MYWEBSITE.com";
$pathNew = "";
$image1Path ="{image1}";
$newPath1 = str_replace($pathStrip, $pathReplace, $ $imagePath1);


Then using

Code: Select all

"source"=>$newPath1,'
in the array, but that didn't work either.

I was thinking that I could use str_replace or preg_replace, but I tried both of them in the datagrid and in datagrid.class.php and they didn't seem to work. is there something I can put in target_path, host or another portion of the array that will accomplish this?

What I need to know is how do I remove the '/home/ACCOUNT/public_html/MYWEBSITE.com' so that the image displays correctly?

Thanks in advance for your help. There are a lot of smart people on this forum, so I'm hoping you guys will have some ideas. This is a great script and I can't wait to fully deploy it.

Cheers,

Erich

administrator
Site Admin
Site Admin
Posts: 6066
Joined: Jan 7th, '09, 23:18
Contact:

Re: Replacing Image Path for Display

Postby administrator » Aug 22nd, '10, 12:28

create function image_replace(), call it via "on_item_created"=>"image_replace"
and do in this function what you need:

function image_replace($value){
$value = replace ......
}

Also, get here more info:
viewtopic.php?f=33&t=176


Return to “Field type: "image/file"”