-3

I have an array of image filenames, which is being passed through a contact form, and being sent as an email to the site owner (these images are uploads, but that part all works fine).

$Images = $_POST['images6ex'] prints the array, and I'm using $result = implode(', ', $Images); to make it more readable.

I'd like to be able to add a base URL to each of the imploded results, so the email recipient can just click (or copy/paste) the link in the email rather than logging into the ftp each time. Is this possible? There's no need to wrap it in a href tag I don't think.

I tried:

$fullurl = array($baseurl,$Images);
$result = implode(', ', $fullurl);

but I just get

http://whatever.com/files/, Array

as the output.

My final output needs to be a variable, as this is how the email body is built: http://pastebin.com/JJSW3Jbg. I'm not sure if that's the most effective way to build the email body, but it works...

Dave
  • 498
  • 2
  • 7
  • 22

2 Answers2

2

The shortest (although not very elegant) solution would probably be:

$result = $baseurl.implode(', '.$baseurl, $Images);

This prepends every element of $baseurl with $baseurl except the first one (because that's how implode works), and then prepends the entire result with it as well, to fix the first element.

Siguza
  • 21,155
  • 6
  • 52
  • 89
  • Thanks - this is spot on and works a treat. It mightn't be the neatest way of doing things, but your answer was very helpful. – Dave Apr 21 '15 at 09:17
0

You'll need to loop to add it to every element in the array, that won't happen just like that. The most elegant method is array_map:

echo join(', ', array_map(
    function ($url) use ($baseurl) { return "$baseurl/$url"; },
    $Images
));
deceze
  • 510,633
  • 85
  • 743
  • 889