if file exists

Reply

Join Date: Feb 2008
Posts: 347
Reputation: kevin wood is an unknown quantity at this point 
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz

if file exists

 
0
  #1
May 6th, 2008
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.

  1. $image = "";
  2. $web_image_folder = 'http://www.acmeart.co.uk/mercury/image/thumbs';
  3. $exts = array('jpg', 'png', 'gif', 'jpeg');
  4. $image_name = 'thumb_image1';
  5.  
  6.  
  7. // check for each extension
  8. foreach($exts as $ext) {
  9. if (file_exists($web_image_folder.'/'.$image_name.'.'.$ext)) {
  10. $image = $image_name.'.'.$ext;
  11. }
  12. }
  13.  
  14. // check if we have an image
  15. if ($image != "") {
  16. // ok we have the image
  17. $broad_img1='<img src="' . $web_image_folder."/".$image . '" />';
  18. } else {
  19. // error, we can't find the image.
  20. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 141
Reputation: robothy is an unknown quantity at this point 
Solved Threads: 19
robothy robothy is offline Offline
Junior Poster

Re: if file exists

 
0
  #2
May 6th, 2008
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 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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 347
Reputation: kevin wood is an unknown quantity at this point 
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz

Re: if file exists

 
0
  #3
May 6th, 2008
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.
Last edited by kevin wood; May 6th, 2008 at 9:41 am.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 141
Reputation: robothy is an unknown quantity at this point 
Solved Threads: 19
robothy robothy is offline Offline
Junior Poster

Re: if file exists

 
0
  #4
May 6th, 2008
Hey Kevin,

Yeah, if you can upload some more content, perhaps the HTML email content, then that may help.

Best,
R
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 347
Reputation: kevin wood is an unknown quantity at this point 
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz

Re: if file exists

 
0
  #5
May 6th, 2008
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.

  1. <?
  2. // You may copy this PHP section to the top of file which needs to access after login.
  3. session_start(); // Use session variable on this page. This function must put on the top of page.
  4. if(!session_is_registered("first_name")){ // if session variable "username" does not exist.
  5. header("location:index.php"); // Re-direct to index.php
  6. }
  7. ?>
  8. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  9. <html xmlns="http://www.w3.org/1999/xhtml">
  10. <head>
  11. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  12. <title>Mercury v1.0 | Admin System</title>
  13. <link href="includes/global.css" rel="stylesheet" type="text/css" />
  14. <style type="text/css">
  15. <!--
  16. .mainTxt {font-size: 11px; color:#444444; font-family: Arial, Helvetica, sans;}
  17. .style1 {
  18. font-family: Arial, Helvetica, sans-serif;
  19. font-size: 10px;
  20. color: #666666;
  21. }
  22. .logout {
  23. position: fixed;
  24. width: 50px;
  25. height: 25px;
  26. left: 801px;
  27. top: 57px;
  28. padding: 0px;
  29. z-index: 100;
  30. }
  31. * html .logout {
  32. position: absolute;
  33. top:expression(eval(document.compatMode &&
  34. document.compatMode=='CSS1Compat') ?
  35. documentElement.scrollTop : document.body.scrollTop);
  36. top: 57px;
  37. }
  38. .register {
  39. position: fixed;
  40. width: 110px;
  41. height: 25px;
  42. left: 801px;
  43. top: 5px;
  44. padding: 0px;
  45. z-index: 100;
  46. font-family: Arial, Helvetica, sans-serif;
  47. font-size: 10px;
  48. color: #333333;
  49. }
  50. * html .register {
  51. position: absolute;
  52. top:expression(eval(document.compatMode &&
  53. document.compatMode=='CSS1Compat') ?
  54. documentElement.scrollTop : document.body.scrollTop);
  55. top: 4px;
  56. }
  57. -->
  58. </style>
  59. <link href="includes/admin.css" rel="stylesheet" type="text/css" />
  60. <style type="text/css">
  61. <!--
  62. body {
  63. background-image: url(admin/images/yrepeat.gif);
  64. }
  65. -->
  66. </style></head>
  67.  
  68.  
  69. <body>
  70. <div class="register"> To register another user to Mercury &copy; &reg;<br />
  71. click <a href="join_form.php">here</a> <br/>
  72. </div>
  73. <div class="logout">
  74. <form method='post' action='logout.php'>
  75. <input type='submit' value='logout' name='logout' />
  76. </form>
  77. </div>
  78. <?php
  79. $image = "";
  80. $web_image_folder = 'http://www.acmeart.co.uk/mercury/image/thumbs';
  81. $exts = array('jpg', 'png', 'gif', 'jpeg');
  82. $image_name = 'thumb_image1';
  83.  
  84.  
  85. // check for each extension
  86. foreach($exts as $ext) {
  87. if (file_exists($web_image_folder.'/'.$image_name.'.'.$ext)) {
  88. $image = $image_name.'.'.$ext;
  89. }
  90. }
  91.  
  92. // check if we have an image
  93. if ($image != "") {
  94. // ok we have the image
  95. $broad_img1='<img src="' . $web_image_folder."/".$image . '" />';
  96. } else {
  97. // error, we can't find the image.
  98. }
  99.  
  100.  
  101.  
  102. // construct mailing list array
  103. $merc_list = explode(",",$merc_mailingList);
  104.  
  105. // deploy the emails
  106. for($i=0; $i<count($merc_list); $i++){
  107. $message = '<style type="text/css">body { margin: 0; background: ; background-image: url(); background-repeat: no-repeat;
  108. } .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;}
  109. .style3 {font-family: Geneva, Arial, Helvetica, sans-serif; color: #FFFFFF; font-weight: bold; }
  110. .style1 {font-family: Arial, Helvetica, sans-serif; font-size: 10px;color: #666666;}
  111. </style>';
  112.  
  113. $message .= '<body leftmargin="0" topmargin="0">
  114. <table width="900" border="0" align="center" cellpadding="0" cellspacing="5">
  115. <tr>
  116. <td height="95" colspan="2" scope="col"><img src=http://www.acmeart.co.uk/mercury/layout/BroadsheetSample/broadhead.jpg width="900" height="150"/></td>
  117. </tr>
  118. <tr>
  119. <td height="25" colspan="2" scope="col"><span class="mainTxt"><strong>' . $broad_topictitle1 . '</strong></span></td>
  120. </tr>
  121. <tr>
  122. <th width="23%" height="200" scope="col"><div align="left">' . $broad_img1 . '
  123. <p>&nbsp;</p></div></th>
  124. <td width="77%" scope="col"><table width="99%" border="0" cellpadding="10" cellspacing="0">
  125. <tr>
  126. <td align="left" valign="top"><span class="mainTxt">' . $broad_messagebody1 . '</span></td>
  127. <!-- End Image 1 -->
  128. </tr>
  129. </table>
  130. <p>&nbsp;</p>
  131. <p>&nbsp;</p>
  132. <p>&nbsp;</p>
  133. <p>&nbsp;</p></td>
  134. </tr>
  135. <tr>
  136. <td height="25" colspan="2" scope="col"><span class="mainTxt"><strong>' . $broad_topictitle2 . '</strong></span></td>
  137. </tr>
  138. <tr>
  139. <th width="23%" height="200" scope="col"><div align="left">' . $broad_img2 . '
  140. <p>&nbsp;</p></div></th>
  141. <td width="77%" scope="col"><table width="99%" border="0" cellpadding="10" cellspacing="0">
  142. <tr>
  143. <td align="left" valign="top"><span class="mainTxt">' . $broad_messagebody2 . '</span></td>
  144. <!-- End Image 1 -->
  145. </tr>
  146. </table>
  147. <p>&nbsp;</p>
  148. <p>&nbsp;</p>
  149. <p>&nbsp;</p>
  150. <p>&nbsp;</p></td>
  151. </tr>
  152. <tr>
  153. <td colspan="2" scope="col"><img src="http://www.acmeart.co.uk/mercury/layout/BroadsheetSample/broadfoot.jpg" width="900" height="150" /></td>
  154. </tr>
  155.  
  156. <tr>
  157. <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>
  158. </tr>
  159. </table>
  160. </table>
  161. </body>';
  162.  
  163.  
  164.  
  165. // Contacts
  166. //$replyName = $merc_replyId;
  167. //$replyEmail = $merc_replyAddress;
  168.  
  169. $replyName = "$merc_replyId";
  170. $replyEmail = $merc_list[$i];
  171.  
  172. $contactname = "";
  173. $contactemail = $merc_list[$i];
  174.  
  175. // Subject
  176. $subject = $merc_messageTitle;
  177.  
  178. // Headers
  179. $headers = "MIME-Version: 1.0" . PHP_EOL;
  180. $headers .= "Content-type: text/html; charset=iso-8859-1" . PHP_EOL;
  181. $headers .= "From: ".$replyName." <".$replyEmail.">\r\n" . PHP_EOL;
  182. $headers .= "To: ".$contactname." <".$contactemail.">\r\n" . PHP_EOL;
  183.  
  184.  
  185. mail($contactemail, $subject, $message, $headers);
  186. } // END for
  187.  
  188. ?>
  189. <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>
  190. <div class="fixed5">
  191. <div id="data">
  192. <?php echo date('l dS F Y h:i:s A'); ?>
  193.  
  194. <p><?php printf("Mercury has successfully sent out %d broadcasts.<br />
  195. <BUTTON onclick=\"window.close();\">close this window</BUTTON>
  196. ", count($merc_list)); ?>
  197. </div>
  198. </div>
  199. </body>
  200.  
  201. </html>

sorry about the all the code.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 347
Reputation: kevin wood is an unknown quantity at this point 
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz

Re: if file exists

 
0
  #6
May 6th, 2008
i may be clutching at straws but could it be i have put the if file exists function. i will move this so it is inside the message variable and see if that changes the outcome.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 347
Reputation: kevin wood is an unknown quantity at this point 
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz

Re: if file exists

 
0
  #7
May 6th, 2008
thought as much that didnt work. is it possible to do what i need it to
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 141
Reputation: robothy is an unknown quantity at this point 
Solved Threads: 19
robothy robothy is offline Offline
Junior Poster

Re: if file exists

 
0
  #8
May 6th, 2008
My guess having seen the above would be that the variable $broad_img1 is out of scope... Try declaring it at the top of the script alongside $image = ""; or alternatively, reassign the HTML <img> string to the $image variable again.

R
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 71
Reputation: amigura is an unknown quantity at this point 
Solved Threads: 7
amigura's Avatar
amigura amigura is offline Offline
Junior Poster in Training

Re: if file exists

 
0
  #9
May 6th, 2008
file_exists will not work on http://

  1. $path_image_folder='mercury/image/thumbs';
  2.  
  3. foreach($exts as $ext) {
  4. if (file_exists($path_image_folder.'/'.$image_name.'.'.$ext)) {
  5. $image = $image_name.'.'.$ext;
  6. }
  7. }
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 347
Reputation: kevin wood is an unknown quantity at this point 
Solved Threads: 1
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz

Re: if file exists

 
0
  #10
May 7th, 2008
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

  1. '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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 9297 | Replies: 22
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC