| | |
if file exists
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
i am trying to get an image file to display in an email, the file is stored on the server but it will not send the file with the email. i have been working on this code now for a few days and i cannot get it to work.
the files that i need displaying change so i have incorporated an array to get the file extension, the email is sent with all the text and images which have been coded in using the absolute file path but the images i want to get from the if file exists function will no show.
here is the code for the file exist if anyone can see why this is not working please show me.
the files that i need displaying change so i have incorporated an array to get the file extension, the email is sent with all the text and images which have been coded in using the absolute file path but the images i want to get from the if file exists function will no show.
here is the code for the file exist if anyone can see why this is not working please show me.
PHP Syntax (Toggle Plain Text)
$image = ""; $web_image_folder = 'http://www.acmeart.co.uk/mercury/image/thumbs'; $exts = array('jpg', 'png', 'gif', 'jpeg'); $image_name = 'thumb_image1'; // check for each extension foreach($exts as $ext) { if (file_exists($web_image_folder.'/'.$image_name.'.'.$ext)) { $image = $image_name.'.'.$ext; } } // check if we have an image if ($image != "") { // ok we have the image $broad_img1='<img src="' . $web_image_folder."/".$image . '" />'; } else { // error, we can't find the image. }
•
•
Join Date: Jan 2008
Posts: 141
Reputation:
Solved Threads: 19
Hey Kevin,
Just to clarify, are you saying that the images are not found when executing the file_exists command?? If so, have you tried putting a relative file path in, instead of the absolute path?
Beyond that, I cannot see any issues with the code. I might be inclined to change the section
Best,
R.
Just to clarify, are you saying that the images are not found when executing the file_exists command?? If so, have you tried putting a relative file path in, instead of the absolute path?
Beyond that, I cannot see any issues with the code. I might be inclined to change the section
if ($image != "") { for and use is_readable instead, with the relative path passed in again. Just because a file exists, it doesn't mean it is readable.Best,
R.
the images are there weather it is finding them is another question i would need to put in some echo "file found" along the way to see that. but if you can not see a problem with that code then they must be getting found just not getting displayed.
as the images will be sent out in a email the absolute path to them must be used when displaying them. for the file exist part could the image file along with the extension be found using relative paths. would this section work if the relative paths where used.
when it comes to display the image then the absolute path would have be used to displayed the image as it is being sent out in an email.
the file extensions can only ever be gif, jpeg or png files, it there another way you know of i could get the image to display in the email.
i can upload the page which is to be sent out if that would make this problem clearer for you.
as the images will be sent out in a email the absolute path to them must be used when displaying them. for the file exist part could the image file along with the extension be found using relative paths. would this section work if the relative paths where used.
when it comes to display the image then the absolute path would have be used to displayed the image as it is being sent out in an email.
the file extensions can only ever be gif, jpeg or png files, it there another way you know of i could get the image to display in the email.
i can upload the page which is to be sent out if that would make this problem clearer for you.
Last edited by kevin wood; May 6th, 2008 at 9:41 am.
sorry about that just been having ago at the Norton consultants. they want £70 to remove a virus when i have already paid for my license cheeky bast***s. here is all the code for the send email page.
sorry about the all the code.
PHP Syntax (Toggle Plain Text)
<? // You may copy this PHP section to the top of file which needs to access after login. session_start(); // Use session variable on this page. This function must put on the top of page. if(!session_is_registered("first_name")){ // if session variable "username" does not exist. header("location:index.php"); // Re-direct to index.php } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Mercury v1.0 | Admin System</title> <link href="includes/global.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- .mainTxt {font-size: 11px; color:#444444; font-family: Arial, Helvetica, sans;} .style1 { font-family: Arial, Helvetica, sans-serif; font-size: 10px; color: #666666; } .logout { position: fixed; width: 50px; height: 25px; left: 801px; top: 57px; padding: 0px; z-index: 100; } * html .logout { position: absolute; top:expression(eval(document.compatMode && document.compatMode=='CSS1Compat') ? documentElement.scrollTop : document.body.scrollTop); top: 57px; } .register { position: fixed; width: 110px; height: 25px; left: 801px; top: 5px; padding: 0px; z-index: 100; font-family: Arial, Helvetica, sans-serif; font-size: 10px; color: #333333; } * html .register { position: absolute; top:expression(eval(document.compatMode && document.compatMode=='CSS1Compat') ? documentElement.scrollTop : document.body.scrollTop); top: 4px; } --> </style> <link href="includes/admin.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- body { background-image: url(admin/images/yrepeat.gif); } --> </style></head> <body> <div class="register"> To register another user to Mercury © ®<br /> click <a href="join_form.php">here</a> <br/> </div> <div class="logout"> <form method='post' action='logout.php'> <input type='submit' value='logout' name='logout' /> </form> </div> <?php $image = ""; $web_image_folder = 'http://www.acmeart.co.uk/mercury/image/thumbs'; $exts = array('jpg', 'png', 'gif', 'jpeg'); $image_name = 'thumb_image1'; // check for each extension foreach($exts as $ext) { if (file_exists($web_image_folder.'/'.$image_name.'.'.$ext)) { $image = $image_name.'.'.$ext; } } // check if we have an image if ($image != "") { // ok we have the image $broad_img1='<img src="' . $web_image_folder."/".$image . '" />'; } else { // error, we can't find the image. } // construct mailing list array $merc_list = explode(",",$merc_mailingList); // deploy the emails for($i=0; $i<count($merc_list); $i++){ $message = '<style type="text/css">body { margin: 0; background: ; background-image: url(); background-repeat: no-repeat; } .mainTxt {font-size: 11px; color:#444444; font-family: Arial, Helvetica, sans;} .whiteTxt {font-size: 9px; color:#FFFFFF; font-family: Arial, Helvetica, sans;} a:link {color:#EB7324} ul {font-size: 9px; color:#EB7324;padding-left: 5px;} .style3 {font-family: Geneva, Arial, Helvetica, sans-serif; color: #FFFFFF; font-weight: bold; } .style1 {font-family: Arial, Helvetica, sans-serif; font-size: 10px;color: #666666;} </style>'; $message .= '<body leftmargin="0" topmargin="0"> <table width="900" border="0" align="center" cellpadding="0" cellspacing="5"> <tr> <td height="95" colspan="2" scope="col"><img src=http://www.acmeart.co.uk/mercury/layout/BroadsheetSample/broadhead.jpg width="900" height="150"/></td> </tr> <tr> <td height="25" colspan="2" scope="col"><span class="mainTxt"><strong>' . $broad_topictitle1 . '</strong></span></td> </tr> <tr> <th width="23%" height="200" scope="col"><div align="left">' . $broad_img1 . ' <p> </p></div></th> <td width="77%" scope="col"><table width="99%" border="0" cellpadding="10" cellspacing="0"> <tr> <td align="left" valign="top"><span class="mainTxt">' . $broad_messagebody1 . '</span></td> <!-- End Image 1 --> </tr> </table> <p> </p> <p> </p> <p> </p> <p> </p></td> </tr> <tr> <td height="25" colspan="2" scope="col"><span class="mainTxt"><strong>' . $broad_topictitle2 . '</strong></span></td> </tr> <tr> <th width="23%" height="200" scope="col"><div align="left">' . $broad_img2 . ' <p> </p></div></th> <td width="77%" scope="col"><table width="99%" border="0" cellpadding="10" cellspacing="0"> <tr> <td align="left" valign="top"><span class="mainTxt">' . $broad_messagebody2 . '</span></td> <!-- End Image 1 --> </tr> </table> <p> </p> <p> </p> <p> </p> <p> </p></td> </tr> <tr> <td colspan="2" scope="col"><img src="http://www.acmeart.co.uk/mercury/layout/BroadsheetSample/broadfoot.jpg" width="900" height="150" /></td> </tr> <tr> <td height="13" colspan="2" scope="col"><div align="justify"><span class="style1">Linacre Voice is a monthly bulletin from LinacreOne Community Partnership 140-142 Linacre Road Litherland L21 8JU Tel: (0151) 922 4898 Open Monday - Thursday 10:00am - 4:00pm <font size="1"></font></span> </div></td> </tr> </table> </table> </body>'; // Contacts //$replyName = $merc_replyId; //$replyEmail = $merc_replyAddress; $replyName = "$merc_replyId"; $replyEmail = $merc_list[$i]; $contactname = ""; $contactemail = $merc_list[$i]; // Subject $subject = $merc_messageTitle; // Headers $headers = "MIME-Version: 1.0" . PHP_EOL; $headers .= "Content-type: text/html; charset=iso-8859-1" . PHP_EOL; $headers .= "From: ".$replyName." <".$replyEmail.">\r\n" . PHP_EOL; $headers .= "To: ".$contactname." <".$contactemail.">\r\n" . PHP_EOL; mail($contactemail, $subject, $message, $headers); } // END for ?> <div class="fixed2"><img src="admin/images/content_header.gif" alt="content header" width="648" height="281" class="fixed2" /></div><div class="fixed1"><img src="admin/images/navbg.gif" alt="nav bg" width="152" height="600" /></div> <div class="fixed5"> <div id="data"> <?php echo date('l dS F Y h:i:s A'); ?> <p><?php printf("Mercury has successfully sent out %d broadcasts.<br /> <BUTTON onclick=\"window.close();\">close this window</BUTTON> ", count($merc_list)); ?> </div> </div> </body> </html>
sorry about the all the code.
file_exists will not work on http://
PHP Syntax (Toggle Plain Text)
$path_image_folder='mercury/image/thumbs'; foreach($exts as $ext) { if (file_exists($path_image_folder.'/'.$image_name.'.'.$ext)) { $image = $image_name.'.'.$ext; } }
robothy
thanks for the reply i will try that and see if that has any effect on the outcome.
amigura
since the images will be sent out as part of an email i need the absolute path with them. so for the if file exists section if i use relative paths there that would work. when it comes to displaying them could i write something like
would that code work i will try it anyway but if it is wrong can you please show me where i went wrong.
thanks for the reply i will try that and see if that has any effect on the outcome.
amigura
since the images will be sent out as part of an email i need the absolute path with them. so for the if file exists section if i use relative paths there that would work. when it comes to displaying them could i write something like
PHP Syntax (Toggle Plain Text)
'http://www.acmeart.co.uk."/". $web_image_folder."/".$image . '
would that code work i will try it anyway but if it is wrong can you please show me where i went wrong.
![]() |
Similar Threads
- Ajax javascript test if image file exists (JavaScript / DHTML / AJAX)
- File I/O Help (C)
- ofstream - detect if file has been deleted between open and close (C++)
- Help!! Applet only works in AppletViewer but not in html file with <applet> tags!!! (Java)
- file help (C++)
- to delete contents of a text file (Java)
- PHP file handling (PHP)
- Bridge.dll error please help me here is my hijackthis log file! (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: Deleting A file on the FTP via php script
- Next Thread: Basic PHP Includes
Views: 9297 | Replies: 22
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database dataentry date directory display download dynamic echo email error file files firstoptioninphpdroplist folder form forms freelancing function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table tutorial tutorials update updates upload url validation validator variable video web white xml youtube





