Jump to content

scorponok

Members
  • Posts

    11
  • Joined

  • Last visited

    Never

Posts posted by scorponok

  1. here is the resize image script

    $columns     = 5;
    $thmb_width  = 120;
    $thmb_height = 80;
    
    function resizeImage($originalImage,$toWidth,$toHeight){
        
        // Get the original geometry and calculate scales
        list($width, $height) = getimagesize($originalImage);
        $xscale=$width/$toWidth;
        $yscale=$height/$toHeight;
        
        // Recalculate new size with default ratio
        if ($yscale>$xscale){
            $new_width = round($width * (1/$yscale));
            $new_height = round($height * (1/$yscale));
        }
        else {
            $new_width = round($width * (1/$xscale));
            $new_height = round($height * (1/$xscale));
        }
        // Resize the original image
        $imageResized = imagecreatetruecolor($new_width, $new_height);
        $imageTmp     = imagecreatefromjpeg ($originalImage);
        imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    
        return $imageResized;
    } 
    
    function generateThumbnails(){
    global $thmb_width,$thmb_height;
    
    // Open the actual directory
    if ($handle = opendir(".")) {
    	// Read all file from the actual directory
    	while ($file = readdir($handle))  {
    		// Check whether tha actual item is a valid file
    		if (is_file($file)){
    			// Check whether the actual image is a thumbnail
          		if (strpos($file,'_th.jpg')){
          			$isThumb = true;
          		} else {
    	      		$isThumb = false;
    	      	}
          	  {continue;}
          		if (!$isThumb) {
    	      		// Process the file string
          			$dirName  = substr($file,0,strpos($file,basename($file)));
          			if (strlen($dirName) < 1) $dirName = '.';
          			$fileName = basename($file);
          			$fileMain = substr($fileName,0,strrpos($fileName,'.'));
          			$extName  = substr($fileName,strrpos($fileName,'.'),
          								strlen($fileName)-strrpos($fileName,'.'));
      					
          			// Check if the actual file is a jpeg image
          			if (($extName == '.jpg') || ($extName == '.jpeg')){
    		    		$thmbFile = $dirName.'/'.$fileMain.'_th.jpg';
    		    		// If a thumbnail dosn't exists then create a new one
    		    		if (!file_exists($thmbFile)){
    			    		imagejpeg(resizeImage($file,$thmb_width,$thmb_height),$thmbFile,80);
    			    	}
    				}
          		} 
       		}
       		}
    }
    
    }
    
    function getNormalImage($file){
    $base = substr($file,0,strrpos($file,'_th.jpg'));
    if (file_exists($base.'.jpg')) return $base.'.jpg';
    elseif (file_exists($base.'.jpeg')) return $base.'.jpeg';
    else return "";
    }
    
    function displayPhotos(){
    global $columns;
    
    generateThumbnails();
    $act = 0;
    // Open the actual directory
    if ($handle = opendir(".")) {
    	// Read all file from the actual directory
    	while ($file = readdir($handle))  {
    		// Check whether tha actual item is a valid file
    		if (is_file($file)){
    			// Check whether the actual image is a thumbnail
          		if (strpos($file,'_th.jpg')){
    				++$act;
    				if ($act > $columns) {
    					echo '</tr><tr><td class="photo"><a href="'.getNormalImage($file).'"><img src="'.$file.'" alt="'.$file.'"/></a></td>';	
    					$act = 1;
    				} else {
    					echo '<td class="photo"><a href="'.getNormalImage($file).'"><img src="'.$file.'" alt="'.$file.'"/></a></td>';	
    				}
          			
          		}
          	}
    	}
    }	
    }
    
    

  2. hi, tired that the images did not display at all. I also realised i didn't include the entire script here is the form part etc..

     

    <?php
    // CHANGE PARAMETERS HERE BEGIN
    $senderName  = " Holidays From Home "; // Eg.: John's Postcards
    $senderEmail = "holidaysfromhome@voluntary.awardspace.co.uk";  // Eg.: john@postcard.com
    // Change only if you have problems with urls
    $postcardURL = "http://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"];
    // CHANGE PARAMETERS HERE END
    $result = 0;
    $msg = "";
    $msg1 = "";
    $pic = "";
    
    function displayPhotos() //edit photos and change image sizes 
    {
    global $pic;
        $columns = 5;
        $count = 0;
    $act = 0;
    $act1 = 0;
    $sel = 0;
        $checked = 0;
        //Get all thumb files
        $thumbs = glob('thumbs/*_th.jpg');
        // Read all file from the actual directory
        foreach($thumbs as $file)
        {
            $count++;
            //Open row if first record for row
            if($count%$columns==1) { echo "<tr>"; }
    
            $checked = (isset($pic[1]) && $pic[1]==$count) ? ' checked="checked"' : '';
            //displays the images
            echo "<td align=\"center\">";
            echo "<img src=\"thumbs/{$file}\" alt=\"postcard\" border=\"1\"/><br/>";
            echo "<input type=\"radio\" name=\"selimg\" value=\"{$file},{$act1}\"{$checked}/>";
            echo "</td>";
            $act++;
            $act1++;
            //Close row if columns count reached
            if($count%$columns==0) { echo "</tr>"; }
        }
        //Close last row
        if($count%$columns!=0) { echo "</tr>"; }
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>Micro Postcard</title>
    <link href= "style/style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <div id="main">
    <div class="style1" id="caption">
    <div align="left" class="style1"></div>
    </div>
       <?php //makes sure form is correctly filled in 
        if(!empty($_POST["submit"]))
    {
      if(empty($_POST["selimg"])){$msg = "Please select an image from above!";$result = 3;}
      else{$pic = explode(",",$_POST["selimg"]);}
      if(empty($_POST["email"]) && empty($result)){$msg1 = "You must enter an email address!";$result = 3;}
      $secCode = empty($_POST["secCode"]) ? "" : strtolower($_POST["secCode"]);
      if($secCode == $_SESSION["securityCode"] && $result != 3) //if security code is successfull continue sending script
      {
       $filename = date("YmdGis");
       $f = fopen("messages/".$filename.".txt","w+");
       fwrite($f,$pic[0]."\n");
       fwrite($f,$_POST['email']."\n");
       fwrite($f,stripslashes($_POST["message"])."\n");
       fclose($f);
       // Message displayed in email note \r\n lines to create lines 
       $from = "From: $senderName <$senderEmail>\r\n";
       $replay = "Reply-To: $senderEmail\r\n";    
       $params = "MIME-Version: 1.0\r\n";
       $params .= "Content-type: text/plain; charset=iso-8859-1\r\n";
       $mailtext = "You have just received a Virtual Postcard!\r\n\r\n
                    You can pick up your postcard at the following web address:\r\n
                    $postcardURL?show=$filename\r\n\r\n
                    We hope you enjoy your postcard, and if you do, please take a moment to send a few yourself!\r\n\r\n
                    Regards,\r\n
                    Holidays From Home\r\n
                    $postcardURL"; //URL of psotcard image
       // Send email
       @mail($_POST["email"],"You've received a postcard",$mailtext,$from.$replay.$params);
          echo "<center>
              Your postcard was sent successfully!<br /><br /> 
              <img src='images/$pic[0]' alt='postcard' /><br /><br /><br />".stripslashes($_POST["message"]). //message displayed if postcard sent successfully
            "</center>";
       $result = 1;
       
       }
      else{if($result != 3){$result = 2;}}
      }
    if(!empty($_GET["show"]))
    {
      $file = $_GET["show"];
      $content = file("messages/$file.txt");
      $pic = $content[0];
      unset($content[0]);
      unset($content[1]);
      foreach($content as $value){$main .= $value;}
      echo "<center>
             Your postcard!<br /><br />
             <img src='images/$pic' alt='postcard'/><br /><br /><br />$main
            </center>";
      }
    ?>
    <?php if((empty($result) || $result == 2 || $result == 3) && empty($_GET["show"]))
    { 
    ?>
             <form action='#' method='post'>
             <table align='center'> 
    <?php displayPhotos();?>
    
    
    <?php echo "<div style='color:#f00;font-size:10px;'> $msg </div>" ?>
    </table> 
          <h2>Fill in the Form and then click on Send Card!!</h2>
              <tr><td>Send to (email address):</tr> 
              <input type='text' name='email' size='30' value='<?php echo (isset($_POST["email"])) ? htmlspecialchars($_POST['email']) : '';?>' />
              <?php echo "<div style='color:#f00;font-size:10px;'> $msg1 </div>" ?>
              <p> 
              </p>
              <tr><td>Message:</td><td>  <p>
            <textarea name='message' rows='10' cols='40'<?php echo (isset($_POST["message"])) ? htmlspecialchars($_POST['message']) : '';?> ></textarea>          
                  <p>                <?php echo
       "</td></tr>
              <tr><td colspan='2'> ";
            
    
    	echo "</tr>
            		  <tr>
              		  <td>Security code: <input class='text' name='secCode' type='text' size='10' />
               		  </td><td><img src='securityCode.php' alt='security code' border='1' /></td>
                      </tr>
              		  <tr><td colspan='2'></tr>
    			  <tr><td colspan='2' align='left'><input type='submit' value='Send card!' name='submit'/></td></tr>
             		  </table>
                      </form>";
    			  echo ($result == 2) ? "<div style='color:#f00;font-size:10px;'> Security code invalid!": " </div>";
    
    } 
    ?>

     

    My apoligies about  i wasn't sure if you needed the rest of it or not.

  3. You could add the thumbnail script into the images file i have code here for you to look at. It is actually rather difficult.

     

    <?php
    /*************************************************
    * Micro Photo Gallery
    *
    * Version: 1.0
    * Date: 2007-04-05
    *
    * Usage:
    * Just copy these files into your image folder
    *
    ****************************************************/
    
    $columns     = 5;
    $thmb_width  = 120;
    $thmb_height = 80;
    
    function resizeImage($originalImage,$toWidth,$toHeight){
        
        // Get the original geometry and calculate scales
        list($width, $height) = getimagesize($originalImage);
        $xscale=$width/$toWidth;
        $yscale=$height/$toHeight;
        
        // Recalculate new size with default ratio
        if ($yscale>$xscale){
            $new_width = round($width * (1/$yscale));
            $new_height = round($height * (1/$yscale));
        }
        else {
            $new_width = round($width * (1/$xscale));
            $new_height = round($height * (1/$xscale));
        }
        // Resize the original image
        $imageResized = imagecreatetruecolor($new_width, $new_height);
        $imageTmp     = imagecreatefromjpeg ($originalImage);
        imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
    
        return $imageResized;
    } 
    
    function generateThumbnails(){
    global $thmb_width,$thmb_height;
    
    // Open the actual directory
    if ($handle = opendir(".")) {
    	// Read all file from the actual directory
    	while ($file = readdir($handle))  {
    		// Check whether tha actual item is a valid file
    		if (is_file($file)){
    			// Check whether the actual image is a thumbnail
          		if (strpos($file,'_th.jpg')){
          			$isThumb = true;
          		} else {
    	      		$isThumb = false;
    	      	}
          	
          		if (!$isThumb) {
    	      		// Process the file string
          			$dirName  = substr($file,0,strpos($file,basename($file)));
          			if (strlen($dirName) < 1) $dirName = '.';
          			$fileName = basename($file);
          			$fileMain = substr($fileName,0,strrpos($fileName,'.'));
          			$extName  = substr($fileName,strrpos($fileName,'.'),
          								strlen($fileName)-strrpos($fileName,'.'));
      					
          			// Check if the actual file is a jpeg image
          			if (($extName == '.jpg') || ($extName == '.jpeg')){
    		    		$thmbFile = $dirName.'/'.$fileMain.'_th.jpg';
    		    		// If a thumbnail dosn't exists tahn create a new one
    		    		if (!file_exists($thmbFile)){
    			    		imagejpeg(resizeImage($file,$thmb_width,$thmb_height),$thmbFile,80);
    			    	}
    				}
          		} 
       		}
       		}
    }
    
    }
    
    function getNormalImage($file){
    $base = substr($file,0,strrpos($file,'_th.jpg'));
    if (file_exists($base.'.jpg')) return $base.'.jpg';
    elseif (file_exists($base.'.jpeg')) return $base.'.jpeg';
    else return "";
    }
    
    function displayPhotos(){
    global $columns;
    
    generateThumbnails();
    $act = 0;
    // Open the actual directory
    if ($handle = opendir(".")) {
    	// Read all file from the actual directory
    	while ($file = readdir($handle))  {
    		// Check whether tha actual item is a valid file
    		if (is_file($file)){
    			// Check whether the actual image is a thumbnail
          		if (strpos($file,'_th.jpg')){
    				++$act;
    				if ($act > $columns) {
    					echo '</tr><tr><td class="photo"><a href="'.getNormalImage($file).'"><img src="'.$file.'" alt="'.$file.'"/></a></td>';	
    					$act = 1;
    				} else {
    					echo '<td class="photo"><a href="'.getNormalImage($file).'"><img src="'.$file.'" alt="'.$file.'"/></a></td>';	
    				}
          			
          		}
          	}
    	}
    }	
    }
    
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
    <html>
    <head>
       <title>Micro Photo Gallery</title>
       <link href="style/thumbs.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
      <div id="main">
        <div class="caption">Micro Photo Gallery</div>
          <table align="center"><tr>     
        		<?php displayPhotos(); ?>
          </table>		
        		
    <div id="source">Micro Photo Gallery 1.0</div>
      </div>
    </body>   
    

     

    If you understand anything at all about PHP/Images you should be able to find what you are looking for in here

  4. hi all

    I am finishing off the final touches to my PHP postcard script and want to be able to display thumb file types only

    I have found a script to resize the images but this creates larger ones so i want to be able to switch between the two.

     

    <?php
    // CHANGE PARAMETERS HERE BEGIN
    $senderName  = " Holidays From Home "; // Eg.: John's Postcards
    $senderEmail = "holidaysfromhome@voluntary.awardspace.co.uk";  // Eg.: john@postcard.com
    // Change only if you have problems with urls
    $postcardURL = "http://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"];
    // CHANGE PARAMETERS HERE END
    $result = 0;
    $msg = "";
    $msg1 = "";
    $pic = "";
    
    function displayPhotos() //edit photos and change image sizes 
    {
    global $pic;
    $columns = 5;
    $act = 0;
    $act1 = 0;
    $sel = 0;
      // Open the actual directory
    if($handle = opendir("thumbs"))
    {
      // Read all file from the actual directory
      while($file = readdir($handle))
      {
       if(!is_dir($file))
       {
        if(isset($pic[1]))
        {
         if($pic[1] == $act1){$sel = "checked";}
         else{$sel = "unchecked";}
         }
        if($act == 0){echo "<tr>";}
        echo "<td align='center'><img src='thumbs/$file' alt='postcard' BORDER =1 /><br/><input type='radio' name='selimg' value='$file,$act1' $sel/></td>"; //displays the images
    
    $act++;
        $act1++;
        if($act == $columns){$act = 0;echo "</tr>";}
    
           }
        }
      echo "</tr>";
      }    
    }
    ?>

     

    my thumbnail images all end in (_th.jpg) and my large files all end in (.jpg). I am really stuck any help would be much appreciated  :confused:

     

     

  5. I understand what you mean about $pic but I am unsure as to how to fix it here is line 52:

    echo "<td align='center'><img src='thumbs/$file' alt='postcard'/><br/><input type='radio' name='selimg' value='$file,$act1' $sel/></td>";

     

    In that where would define $pic as a array?

     

    Line 134-5

    <tr><td>Send to (email address):</td><td><div style='color:#f00;font-size:16px;'>$msg1</div><input type='text' name='email' size='30' value='".$_POST["email"]."' /></td></tr>

              <tr><td>Message:</td><td><textarea name='message' rows='10' cols='40'>".stripslashes($_POST["message"])."</textarea></td></tr>

     

    From that It looks to me like it is passing the data through but obviously not.

     

     

  6. :'(

     

    No that unfortunately didn't work at all i get new error messages here:

     

    Notice: Undefined variable: sel in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 52

     

    Notice: Undefined variable: sel in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 52

     

    Notice: Undefined variable: sel in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 52

     

    Notice: Undefined variable: sel in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 52

     

    Notice: Undefined variable: sel in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 52

     

    Notice: Undefined variable: sel in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 52

     

    Notice: Undefined index: email in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 133

     

    Notice: Undefined index: message in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 134

     

    I really am very confused by this :shrug:

  7. hi,

    I need help really badly for my PHP-Postcard Script. Basically it sends the card out but the URL does not work, I get the following error message:

     

    The URL is not valid and cannot be loaded

     

    It also states that

    Notice: Undefined index: www.voluntary.awardspace.co.uk in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 25

    Notice: Undefined index: Postcard.php in /home/www/voluntary.awardspace.co.uk/Postcard.php on line 25

     

    See Code below:

     

    <?php
    
    session_start();
    //check error log
    ini_set('display_errors', 1);
    ini_set('log_errors', 1);
    ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
    error_reporting(E_ALL);
    
    // CHANGE PARAMETERS HERE BEGIN
    $senderName  = " Holidays From Home "; // Eg.: John's Postcards
    $senderEmail = "chris01@voluntary.awardspace.co.uk";  // Eg.: john@postcard.com
    // Change only if you have problems with urls
    $postcardURL = "http://".$_SERVER["www.voluntary.awardspace.co.uk"].$_SERVER["Postcard.php"];
    // CHANGE PARAMETERS HERE END
    $result = 0;
    $msg = "";
    $msg1 = "";
    $pic = "";
    function displayPhotos()
    {
    global $pic;
    $columns = 5;
    $act = 0;
    $act1 = 0;
    // Open the actual directory
    if($handle = opendir("thumbs"))
    {
      // Read all file from the actual directory
      while($file = readdir($handle))
      {
       if(!is_dir($file))
       {
        if(isset($pic[1]))
        {
         if($pic[1] == $act1){$sel = "checked";}
         else{$sel = "unchecked";}
         }
        if($act == 0){echo "<tr>";}
        echo "<td align='center'><img src='thumbs/$file' alt='postcard'/><br/><input type='radio' name='selimg' value='$file,$act1' $sel/></td>";
        $act++;
        $act1++;
        if($act == $columns){$act = 0;echo "</tr>";}
    
           }
        }
      echo "</tr>";
      }    
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>Micro Postcard</title>
    <link href= "style/style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <div id="main">
    <div class="style1" id="caption">
    <div align="left" class="style1"></div>
    </div>
       <?php //makes sure form is correctly filled in 
    if(!empty($_POST["submit"]))
    {
      if(empty($_POST["selimg"])){$msg = "Please select an image from above!";$result = 3;}
      else{$pic = explode(",",$_POST["selimg"]);}
      if(empty($_POST["email"]) && empty($result)){$msg1 = "You must enter an email address!";$result = 3;}
      $secCode = empty($_POST["secCode"]) ? "" : strtolower($_POST["secCode"]);
      if($secCode == $_SESSION["securityCode"] && $result != 3)
      {
       $filename = date("YmdGis");
       $f = fopen("messages/".$filename.".txt","w+");
       fwrite($f,$pic[0]."\n");
       fwrite($f,$_POST['email']."\n");
       fwrite($f,stripslashes($_POST["message"])."\n");
       fclose($f);
       // Compose the mail
       $from = "From: $senderName <$senderEmail>\r\n";
       $replay = "Reply-To: $senderEmail\r\n";    
       $params = "MIME-Version: 1.0\r\n";
       $params .= "Content-type: text/plain; charset=iso-8859-1\r\n";
       $mailtext = "You have just received a Virtual Postcard!\r\n\r\n
                    You can pick up your postcard at the following web address:\r\n
                    $postcardURL?show=$filename\r\n\r\n
                    We hope you enjoy your postcard, and if you do, please take a moment to send a few yourself!\r\n\r\n
                    Regards,\r\n
                    Holidays From Home\r\n
                    $postcardURL";
       // Send email
       @mail($_POST["email"],"You've received a postcard",$mailtext,$from.$replay.$params);
       echo "<center>
              Your postcard was sent successfully!<br /><br />
              <img src='images/$pic[0]' alt='postcard' /><br /><br /><br />".stripslashes($_POST["message"]).
            "</center>";
       $result = 1;
       }
      else{if($result != 3){$result = 2;}}
      }
    if(!empty($_GET["show"]))
    {
      $file = $_GET["show"];
      $content = file("messages/$file.txt");
      $pic = $content[0];
      unset($content[0]);
      unset($content[1]);
      foreach($content as $value){$main .= $value;}
      echo "<center>
             Your postcard!<br /><br />
             <img src='images/$pic' alt='postcard' /><br /><br /><br />$main
            </center>";
      }
    if((empty($result) || $result == 2 || $result == 3) && empty($_GET["show"]))
    {
      echo "<form action='#' method='post'>
             <table align='center'>";
             displayPhotos();
      echo  "</table>
             <div style='color:#f00;font-size:16px;'>$msg</div>        
             <h2>Fill in the Form and then click on Send Card!!</h2>
             <table width='100%'>
              <tr><td>Send to (email address):</td><td><div style='color:#f00;font-size:16px;'>$msg1</div><input type='text' name='email' size='30' value='".$_POST["email"]."' /></td></tr>
              <tr><td>Message:</td><td><textarea name='message' rows='10' cols='40'>".stripslashes($_POST["message"])."</textarea></td></tr>
              <tr><td colspan='2'>".($result == 2 ? "<p style='color:#f00;font-size:16px;'>Sorry the security code is invalid! Please try it again!</span></p>" : " ")."</tr>
              <tr>
               <td>Security code: <input class='text' name='secCode' type='text' size='10' />
               </td><td><img src='securityCode.php' alt='security code' border='1' /></td>
              </tr>
              <tr><td colspan='2'> </tr>
              <tr><td colspan='2' align='left'><input type='submit' value='Send card!' name='submit'/></td></tr>
             </table>
            </form>";
      }
    ?>

     

    Absolutely any help would be much appreciated. I want ot know is there a way round this problem?

     

    Here is the http://voluntary.awardspace.co.uk/Postcard.php

     

    I am absolutely desperate to solve this burning issue  :(

     

  8. hi,

    I am developing a PHP Postcard system with Micro-Captcha Security and i get the following errors:

     

    Internal Server Error, this is an error with your script, check your error log for more information.

     

    or the code simply does not send the script I understand based on research that the problems lies with undefined variables:

    I also used a PHP error code to display errors.

    See code below:

    <?php
    
    session_start();
    //check error log
    ini_set('display_errors', 1);
    ini_set('log_errors', 1);
    ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
    error_reporting(E_ALL);
    
    // CHANGE PARAMETERS HERE BEGIN
    $senderName  = " Holidays From Home "; // Eg.: John's Postcards
    $senderEmail = "chris01@voluntary.awardspace.co.uk";  // Eg.: john@postcard.com
    // Change only if you have problems with urls
    $postcardURL = "http://".$_SERVER["HTTP_HOST"].$_SERVER["SCRIPT_NAME"]; //problem is here perhaps?
    // CHANGE PARAMETERS HERE END
    $result = 0;
    $msg = "";
    $msg1 = "";
    $pic = "";
    function displayPhotos()
    {
    global $pic;
    $columns = 5;
    $act = 0;
    $act1 = 0;
    // Open the actual directory
    if($handle = opendir("thumbs"))
    {
      // Read all file from the actual directory
      while($file = readdir($handle))
      {
       if(!is_dir($file))
       {
        if(isset($pic[1]))
        {
         if($pic[1] == $act1){$sel = "checked";}
         else{$sel = "unchecked";}
         }
        if($act == 0){echo "<tr>";}
        echo "<td align='center'><img src='thumbs/$file' alt='postcard'/><br/><input type='radio' name='selimg' value='$file,$act1' $sel/></td>";
        $act++;
        $act1++;
        if($act == $columns){$act = 0;echo "</tr>";}
    
           }
        }
      echo "</tr>";
      }    
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>Micro Postcard</title>
    <link href= "style/style.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <div id="main">
    <div class="style1" id="caption">
    <div align="left" class="style1"></div>
    </div>
       <?php //makes sure form is correctly filled in 
    if(!empty($_POST["submit"]))
    {
      if(empty($_POST["selimg"])){$msg = "Please select an image from above!";$result = 3;}
      else{$pic = explode(",",$_POST["selimg"]);}
      if(empty($_POST["email"]) && empty($result)){$msg1 = "You must enter an email address!";$result = 3;}
      $secCode = empty($_POST["secCode"]) ? "" : strtolower($_POST["secCode"]);
      if($secCode == $_SESSION["securityCode"] && $result != 3)
      {
       $filename = date("YmdGis");
       $f = fopen("messages/".$filename.".txt","w+");
       fwrite($f,$pic[0]."\n");
       fwrite($f,$_POST['email']."\n");
       fwrite($f,stripslashes($_POST["message"])."\n");
       fclose($f);
       // Compose the mail
       $from = "From: $senderName <$senderEmail>\r\n";
       $replay = "Reply-To: $senderEmail\r\n";    
       $params = "MIME-Version: 1.0\r\n";
       $params .= "Content-type: text/plain; charset=iso-8859-1\r\n";
       $mailtext = "You have just received a Virtual Postcard!\r\n\r\n
                    You can pick up your postcard at the following web address:\r\n
                    $postcardURL?show=$filename\r\n\r\n
                    We hope you enjoy your postcard, and if you do, please take a moment to send a few yourself!\r\n\r\n
                    Regards,\r\n
                    Holidays From Home\r\n
                    $postcardURL";
       // Send email
       @mail($_POST["email"],"You've received a postcard",$mailtext,$from.$replay.$params);
       echo "<center>
              Your postcard was sent successfully!<br /><br />
              <img src='images/$pic[0]' alt='postcard' /><br /><br /><br />".stripslashes($_POST["message"]).
            "</center>";
       $result = 1;
       }
      else{if($result != 3){$result = 2;}}
      }
    if(!empty($_GET["show"]))
    {
      $file = $_GET["show"];
      $content = file("messages/$file.txt");
      $pic = $content[0];
      unset($content[0]);
      unset($content[1]);
      foreach($content as $value){$main .= $value;}
      echo "<center>
             Your postcard!<br /><br />
             <img src='images/$pic' alt='postcard' /><br /><br /><br />$main
            </center>";
      }
    if((empty($result) || $result == 2 || $result == 3) && empty($_GET["show"]))
    {
      echo "<form action='#' method='post'>
             <table align='center'>";
             displayPhotos();
      echo  "</table>
             <div style='color:#f00;font-size:16px;'>$msg</div>        
             <h2>Fill in the Form and then click on Send Card!!</h2>
             <table width='100%'>
              <tr><td>Send to (email address):</td><td><div style='color:#f00;font-size:16px;'>$msg1</div><input type='text' name='email' size='30' value='".$_POST["email"]."' /></td></tr>
              <tr><td>Message:</td><td><textarea name='message' rows='10' cols='40'>".stripslashes($_POST["message"])."</textarea></td></tr>
              <tr><td colspan='2'>".($result == 2 ? "<p style='color:#f00;font-size:16px;'>Sorry the security code is invalid! Please try it again!</span></p>" : " ")."</tr>
              <tr>
               <td>Security code: <input class='text' name='secCode' type='text' size='10' />
               </td><td><img src='securityCode.php' alt='security code' border='1' /></td>
              </tr>
              <tr><td colspan='2'> </tr>
              <tr><td colspan='2' align='left'><input type='submit' value='Send card!' name='submit'/></td></tr>
             </table>
            </form>";
      }
    ?>

     

    Any help would be much appreciated i am really stuck with this code. :(

     

    here is the link:

    http://voluntary.awardspace.co.uk/Postcard.php

     

     

×
×
  • 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.