Jump to content

Recommended Posts

I'm trying to get a table generated for an email script - it looks like this:

 

<tr>
      <td>Front: </td><td><a href="http://localhost/testsite/valuation_images/'.$clientname.'_'.$img_type[$key].'_'.$_FILES[$fieldname]['name'][$key].'">'.$clientname.'_'.$img_type.'_'.$_FILES[$fieldname]['name'][$key].'</a></td>
    </tr>
    <tr>
      <td>Back: </td><td><td><a href="http://localhost/testsite/valuation_images/'.$clientname.'_'.$img_type[$key].'_'.$_FILES[$fieldname]['name'][$key].'">'.$clientname.'_'.$img_type.'_'.$_FILES[$fieldname]['name'][$key].'</a></td>
    </tr>
    <tr>
      <td>Scroll: </td><td><td><a href="http://localhost/testsite/valuation_images/'.$clientname.'_'.$img_type.'_'.$_FILES[$fieldname]['name'][$key].'">'.$clientname.'_'.$img_type.'_'.$_FILES[$fieldname]['name'][$key].'</a></td>
    </tr>
    <tr>
      <td>Detail: </td><td><td><a href="http://localhost/testsite/valuation_images/'.$clientname.'_'.$img_type.'_'.$_FILES[$fieldname]['name'][$key].'">'.$clientname.'_'.$img_type.'_'.$_FILES[$fieldname]['name'][$key].'</a></td>
    </tr>

 

This is all contained in the $message string, to be compiled into an email to be sent out, using mail($recipient, $subject, $message, $headers);... So far so good.

 

I can generate the image link, so that it comes up with the front, back, scroll, detail in the image name.  Here's the code that processes the form and gives me the images, moves them, etc...

// possible PHP upload errors
$errors = array(1 => 'php.ini max file size exceeded',
                2 => 'html form max file size exceeded',
                3 => 'file upload was only partial',
                4 => 'no file was attached');

$img_type = array(0 => 'front',
                1 => 'back',
                2 => 'scroll',
                3 => 'detail');


// check if any files were uploaded and if
// so store the active $_FILES array keys
$active_keys = array();
foreach($_FILES[$fieldname]['name'] as $key => $filename)
{
    if(!empty($filename))
    {
        $active_keys[] = $key;
    }
}

foreach($_FILES[$fieldname]['name'] as $key => $filename)
{
    if(!empty($filename))
    {
        $img_type[] = $key;
    }
}

// make a unique filename for the uploaded file and check it is
// not taken... if it is keep trying until we find a vacant one
foreach($active_keys as $key)
{
    $now = time();
    while(file_exists($uploadFilename[$key] = $uploadsDirectory.$clientname."_".$img_type[$key]."_".$_FILES[$fieldname]['name'][$key]))
    {
        $now++;
    }
}


// now let's move the file to its final and allocate it with the new filename
foreach($active_keys as $key)
{
    //echo $clientname.$uploadFilename[$key];
    //echo $img_type[$key];
    @move_uploaded_file($_FILES[$fieldname]['tmp_name'][$key], $uploadFilename[$key])
        or error('receiving directory insuffiecient permission', $uploadForm);
}

foreach($active_keys as $key) {
    
    echo $uploadFilename[$key];

}

 

But the bit I'm stuck on, it how do I get each individual image to link in the $message string??? So the table would read:

 

Front:  Image_001_front.jpg

Back: Rear_photo_back.jpg

Scroll:

Detail: Close_up_342_detail.jpg

 

?

Link to comment
https://forums.phpfreaks.com/topic/143761-solved-foreach-loop-in-string/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.