richrock Posted February 4, 2009 Share Posted February 4, 2009 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/143761-solved-foreach-loop-in-string/ Share on other sites More sharing options...
richrock Posted February 4, 2009 Author Share Posted February 4, 2009 Figured it out - I break up the $message string by using $message .= ""; Then contain the links in a foreach loop! Sorry 'bout that. Quote Link to comment https://forums.phpfreaks.com/topic/143761-solved-foreach-loop-in-string/#findComment-754276 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.