1

I would like to retrieve the URL to an image so that I can display the image that the user has successfully uploaded in my project. However, upon testing I only have an absolute path. What is the best way to trim this down to a relative path in relation to the URL of the website?

For instance, if I have this: "/home/teonnyn/public_html/app/webroot/thumb/Teonnyn/thumb_ZB6pEaz.jpg"

I would want to convert it to "url.com/thumb/Teonnyn/" and so on. So far, I have a JSON output string that returns the successful upload to Javascript:

header('Content-Type: application/json');

$output = array("thumb" => $ThumbResult, "image" => $FileResult);

$echo = json_encode($output);

echo $echo;

That produces a message containing the absolutes for the thumbnail and the image. It is received by Javascript:

done: function(e, data) {
    console.log("Done!");
    var Obj = data.result;
    var parse = JSON.parse(Obj);
    console.log(parse.thumb);
}

at which point, I can access either .thumb or .image easily, but I am unsure how to finish the conversion steps.

Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
Merlin
  • 929
  • 12
  • 33
  • you can replace `eonnyn/public_html/app/webroot/` with your `URL.com` before getting output using str_replace() function. – Nana Partykar Nov 07 '15 at 09:39

0 Answers0