Jump to content

Recommended Posts

Totally new to php so would have a hard time coding this but sur ei could find a way.

 

Basically i have a textfield that people enter a message in to send an email. And at the end it add's a varible.(the link to a image they have just hosted)

 

Which works fine but some times people want to add the picture where they want to in an email. so for example.

 

"bla bla bla, how are you. Here is Johns new car <image> bla bla bla"

 

Can php split strings and search?

 

this is part of the viewpicture.php,

 

<?

# ignore any invalid requests
if( !ctype_alnum($_GET['file']) ) {
header('Location: Upload.htm');
}

require_once('../inc/mysql.inc.php');

$info_query = 'SELECT `storedname`, `fileext`, UNIX_TIMESTAMP(`uploaded`) FROM `images` WHERE `storedname` = \''.addslashes($_GET['file']).'\'';
$info_result = mysql_query($info_query);
$info_row = mysql_fetch_object($info_result);
$fullname = $info_row->storedname.'.'.$info_row->fileext; 

#add header to page
echo '<link href="index_files/style.css" rel="stylesheet" type="text/css">';
echo '<style type="text/css">';
echo 'a:link {';
echo 'color: #284b72;';
echo '}';
echo '.style1 {';
echo 'font-size: 0.5em';
echo '}';
echo '</style>';

echo '<link rel="SHORTCUT ICON" href="http://www.simplecoders.com/sc.ico"/>';
echo '<div id="outer">';
echo '<div id="header">';
echo '<h1><a href="">SimpleCoders</a></h1>';
echo '<h2 class="style1">The simple coders team 2009</h2>';
echo '</div>';
echo '<div id="menu">';
echo '<ul>';
echo '<li class="first"><a href="index.php" title="Home">Home</a></li>';
echo '<li><a href="About.php" title="">About Us</a></li>';
echo '<li><a href="Products.php" title="">Products</a></li>';
echo '<li><a href="Upload.php" title="">Upload</a></li>';
echo '<li><a href="Contact.php" title="Contact">Contact Us</a></li>';
echo '</ul>';
echo '</div>';
echo '<p></p>';

#echo ''.date('d/m/Y').'<br /><p></p>';
$rawlink = 'http://www.simplecoders.com/showpic.php?f='.$fullname;
$bbcode = '[img='.$rawlink.']'; 
$htmlimg = '<img src="'.$rawlink.'" />'; 

echo '<div style="text-align: center;">';
echo '<br /><h2>Share This Image</h2> <br/>';
echo 'HTML for Websites:<br /><input name="html" style="width:300px;"type="text" value="'.htmlentities($htmlimg, ENT_QUOTES).'" /><br />';
echo 'IMG Code for Forums & Message Boards:<br /><input style="width:300px;" type="text" value="'.$bbcode.'" /><br />';
echo 'Direct Link for Layouts:<br /><input style="width:300px;" type="text" value="'.$rawlink.'" /><br />';
echo '<br /><a href="Upload.php"><img src="uploadMore.PNG" STYLE="position:absolute; TOP:302px; LEFT:363px;" /> </a>';

echo '</div>';


echo '<a href="./showpic.php?f='.$fullname.'"><img src="./showpic.php?f='.$fullname.'"width="150" height="150" STYLE="position:absolute; TOP:195px; LEFT:800px;"  /></a><br />';

echo '<div style="position: absolute; top: 355px; left: 800px;">';
echo '<a href="'.$rawlink.'"><b><u>View Full Sized Image</b></u></a>';
echo '</div>';

echo '<div style="position: absolute; top: 380px; left: 800px;">';
echo '<a href="Email.php?file='.$info_row->storedname.'.'.$info_row->fileext.'"><b><u>E-Mail Image</b></u></a>';
echo '</div>';

$htmlLink = $_POST['html'];

?>

 

Email.php

 

<?php

include('header.php');

if( preg_match('/[a-zA-Z0-9]+.+/', $_GET['file']) ) {
$htmllink ='http://www.simplecoders.com/showpic.php?f='.$_GET['file'];	
}

?>

<input type="hidden" name="rawlink" value="<?php echo $htmllink; ?>" />

 

 

Then the actual sending of the email

 

<?php
//add the header
include('header.php');

//define the receiver of the email
$to = $_POST["to"];
//define the subject of the email
$subject = htmlentities($_POST["subject"], ENT_QUOTES);
//define the message to be sent. Each line should be separated with \n

// http://www.simplecoders.com/showpic.php?f=IR6eC3zS2w41wA.jpg
$url_bits = parse_url($_POST['rawlink']);
if( !preg_match('/f=[a-z-A-Z0-9]+\.[a-z]{1,3}/', $url_bits['query']) ) {
echo "bad link";
die;
}

$message =  htmlentities($_POST["msg"], ENT_QUOTES);
$message .= '<br /><img src="'.$_POST['rawlink'].'" />';

$headers = "From: SimpleCoders\r\nReply-To: support@simplecoders";
//send the email
$mail_sent = @mail( $to, $subject, $message, $headers );

echo $mail_sent ? "<br /><center>Mail sent" : "Mail failed";
echo "<br /><a href=\"Upload.php\">Click here to go back to the previous page</a></center>";

?>

Link to comment
https://forums.phpfreaks.com/topic/175928-string-splitting/
Share on other sites

I am still not entirely sure what you want to do?  Are you trying to find an instance of a string within a string an then do something based on the presence (or absence) of that substring?

 

bla bla bla, how are you. Here is Johns new car <image> bla bla bla

 

"if the string '<image>' is found withing the string 'text' then do xyz, otherwise do abc"

 

Is that what your trying to do?

Link to comment
https://forums.phpfreaks.com/topic/175928-string-splitting/#findComment-927021
Share on other sites

Hi, let me try to explain a bit more.

 

My site hosts images. When the site displays the thumb nail, under it  has a link called email. When clicked it goes to a page with 2 textboxs and a texfield.

 

"To: Subject: Message:" this allows the user to email the image to a friend. Currently this only adds the image link to the end of the email.

 

What i would to do is for a user when typing the message to be able to choose where in the email the image should go. using a tag <image>.

 

"This is my email message <imagehere> and so on"

 

where the tag is placed is where php adds the link i have saved.

Link to comment
https://forums.phpfreaks.com/topic/175928-string-splitting/#findComment-927028
Share on other sites

Simply do a find and replace. Choose something that the user is unlikely to want to use in their message. So for example you could tell the user to put [iMAGE] wherever they want the image to appear. Then before you send the e-mail you $message = str_replace('[iMAGE]', $link, $message);

Link to comment
https://forums.phpfreaks.com/topic/175928-string-splitting/#findComment-927035
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.