User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 361,556 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,007 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1311 | Replies: 22
Reply
Join Date: Feb 2008
Posts: 259
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

if file exists

  #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.

$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.
}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Posts: 37
Reputation: robothy is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
robothy robothy is offline Offline
Light Poster

Re: if file exists

  #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  
Join Date: Feb 2008
Posts: 259
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: if file exists

  #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 8:41 am.
Reply With Quote  
Join Date: Jan 2008
Posts: 37
Reputation: robothy is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
robothy robothy is offline Offline
Light Poster

Re: if file exists

  #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  
Join Date: Feb 2008
Posts: 259
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: if file exists

  #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.

<?
// 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 &copy; &reg;<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>&nbsp;</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>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</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>&nbsp;</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>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
        <p>&nbsp;</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.
Reply With Quote  
Join Date: Feb 2008
Posts: 259
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: if file exists

  #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  
Join Date: Feb 2008
Posts: 259
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: if file exists

  #7  
May 6th, 2008
thought as much that didnt work. is it possible to do what i need it to
Reply With Quote  
Join Date: Jan 2008
Posts: 37
Reputation: robothy is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 5
robothy robothy is offline Offline
Light Poster

Re: if file exists

  #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  
Join Date: Jan 2008
Posts: 71
Reputation: amigura is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 7
amigura's Avatar
amigura amigura is offline Offline
Junior Poster in Training

Re: if file exists

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

$path_image_folder='mercury/image/thumbs';

foreach($exts as $ext) {
   if (file_exists($path_image_folder.'/'.$image_name.'.'.$ext)) {
     $image = $image_name.'.'.$ext;
   }
}
Reply With Quote  
Join Date: Feb 2008
Posts: 259
Reputation: kevin wood is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
kevin wood's Avatar
kevin wood kevin wood is offline Offline
Posting Whiz in Training

Re: if file exists

  #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

'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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 2:23 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC