PHP - Imap_open - Getting Attached Images
Hi
I have the following code, which works fine.
How can I pull in any images attached to the email and display them under the echo $val ?
Thanks
$mbox = imap_open("{SERVER}", "user", "pass"); echo "<h1>Mailboxes</h1>\n"; $folders = imap_listmailbox($mbox, "{SERVER}", "*"); if ($folders == false) { echo "Call failed<br />\n"; } else { foreach ($folders as $val) { echo $val . "<br />\n"; } } echo "<h1>INBOX</h1>\n"; $headers = imap_headers($mbox); if ($headers == false) { echo "Call failed<br />\n"; } else { $i=0; foreach ($headers as $val) { $i++; echo $val . "<br />\n"; } } imap_close($mbox); Similar TutorialsHi all,
I need some help with my code as I've a trouble with sending the emails with images attachments. I'm using Pear Mail library to send the emails so when I send the emails with attachments to gmail, I am unable to see the attached images in my gmail inbox as there is no images show on the bottom of the subject unless when I open on my email so I can see the images attachments. And I am unable to see the images on yahoo when i sent the emails, so I sent a test email on my webmail with the images as attachments and I can see the images on gmail and yahoo with no problem. I think there is a problem with my PHP script that need to be resolve. //attachments if (is_array($email_attachments)) { foreach ($email_attachments as $attachments) { $filename = str_replace('uploads/', '', $attachments); $attachment = ''; $file_path = ''; $type = ''; if (strpos($filename, '.png') !== false) { $type .= 'image/png'; } // ADD attachment(s) $attachment1 .= "--$boundary1\r\n"; $attachment1 .= "Content-Type: $type; name=\"$filename\"\r\n"; $attachment1 .= "Content-Transfer-Encoding: base64\r\n"; $attachment1 .= "Content-Disposition: attachment; filename=\"$filename\"\r\n"; $attachment1 .= "\r\n\r\n"; $attachment1 .= $attachment; $attachment1 .= "\r\n\r\n"; $body .= $attachment1; $mime->addAttachment($file_path, $type); } }
Here is the full code: <?php require_once('Mail.php'); require_once('Mail/mime.php'); require_once('Mail/IMAPv2.php'); ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); //Connect to the database include('config.php'); // Connect to the server: $username = 'myusername'; $password = 'mypassword'; $smtp_hostname = "smtp.mydomain.com"; $port = "587"; $attached_files = array(); $inline_images = array(); global $inline_images; if (isset($_POST['send_to'])) { $from = "Mark <name@mydomain.com>"; $to_email = $_POST['send_to']; $subject = $_POST['email_subject']; $message ='<div dir="ltr">' . $_POST['email_body'] . '</div>'; $email_attachments = $_POST['email_attachment']; $total_emails = count($to_email); $email_number = $_POST['email_number']; $sent_message = $message; $attachment1 = ''; $inline_id = 0.1; $success = ''; $base64 = []; $src = []; //Check if the images is base64 if (strpos($message, 'data:image/') !== false) { // read all image tags into an array preg_match_all('/<img.*?src="data:image\/.*;.*,(.*)".*?>/i', $message, $match, PREG_PATTERN_ORDER); $base64 = array_pop($match); if (is_array($src)) { foreach($base64 as $images) { $type = end(explode('/', (explode(';', $images))[0])); $filename = md5(time().uniqid()). '.' . $type; $base64_string = str_replace('data:image/png;base64,', '', $images); $base64_string = str_replace(' ', '+', $base64_string); $decoded = base64_decode($base64_string); $fp = fopen("uploads/". $filename, "w+"); fwrite($fp, $decoded); fclose($fp); } } } //check if the inline images is in the array if (strpos($message, '<img src=') !== false) { // read all image tags into an array preg_match_all('@src="([^"]+)"@' , $message, $match); $src = array_pop($match); if (is_array($src)) { foreach ($src as $key => $value) { $parsed = parse_url($src[$key]); $filename = basename($parsed['path']); $content = file_get_contents($src[$key]); if (!file_exists($filename)) { $fp = fopen("uploads/". $filename, "w+"); fwrite($fp, $content); fclose($fp); } } } } $boundary1 = '###'.md5(microtime()).'###'; $boundary2 = '###'.md5(microtime().rand(99,999)).'###'; foreach ($to_email as $to) { $name = ''; $email = ''; if (strpos($to, ' <') !== false) { $name_str = explode(' <', $to); $email_str = explode(' <', $to); $name = $name_str[0]; $email = str_replace('>', '', $email_str); $email = $email[1]; } $messageID = sprintf("<%s.%s@%s>", base_convert(microtime(), 10, 36), base_convert(bin2hex(openssl_random_pseudo_bytes(8)), 16, 36), 'mydomain.com'); $message_id = getMessageid(isset($message_id)); $now = new DateTime(); $email_id = $now->getTimestamp(); $sent_date = date('Y-m-d H:i:s'); $sent_mailbox1 = $link->prepare("SELECT * FROM sent WHERE message_id = ?"); $sent_mailbox1->execute([$message_id]); $emailID = ''; if (!$name == '' && !$email == '') { if ($name == $email) { $to = $email; } } if ($sent_mailbox1->rowCount() == 0) { $sent_mailbox1 = $link->prepare("INSERT INTO sent (from_email, to_email, message_id) VALUES (?,?,?)"); if ($sent_mailbox1->execute([$from, $to, $message_id])) { $emailID = $link->lastInsertId(); } } //check if the images is base64 if (is_array($base64)) { $sent_message .= 'http://mydomain.com/u/?id='.$email_id.'&attid='.$inline_id.'&msgid='.$message_id.'&view=attachment&display=view'; $inline_id += 0.1; } else if (!$base64 == '') { $sent_message .= 'http://mydomain.com/u/?id='.$email_id.'&attid='.$inline_id.'&msgid='.$message_id.'&view=attachment&display=view'; $inline_id += 0.1; } //check if the inline images is in the array if (is_array($src)) { $sent_message .= 'http://mydomain.com/u/?id='.$email_id.'&attid='.$inline_id.'&msgid='.$message_id.'&view=attachment&display=view'; $inline_id += 0.1; } else if (!$src == '') { $sent_message .= 'http://mydomain.com/u/?id='.$email_id.'&attid='.$inline_id.'&msgid='.$message_id.'&view=attachment&display=view'; $inline_id += 0.1; } $message .= '<img src="http://mydomain.com/track/Images/signature.gif?id='.$emailID.'&etc='.time(). '" ' . 'style="width:0;max-height:0;overflow:hidden" alt="">'; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject, 'Reply-To' => $from, //'Content-Type' => 'Content-Type: text/plain; charset="UTF-8"', 'Content-Type' => 'Content-Type: multipart/mixed; boundary="=_d909e7abc497193ad3b6636530382391"', 'MIME-Version' => '1.0', 'Received' => 'from mail.mydomain.com', 'Date' => date("r"), 'Message-ID' => '<'.sha1(microtime(true)).'@mydomain.com>'); $crlf = "\r\n"; $mime = new Mail_mime(array('eol' => $crlf)); //$mime = new Mail_mime("\r\n"); $html = $message; $text = strip_tags($html); $body = $html; $mime->setTXTBody($text); $mime->setHTMLBody($html); //check if the img tags have url called display=view if (strpos($message, 'display=view') !== false) { $pattern = '@src="([^"]+)"@'; $message = preg_replace_callback($pattern,"setImageLinks", $message); foreach ($inline_images as $inline_image) { $file_path = $inline_image; $typeInt = imagetype($file_path); //code goes here to find the imagetype case switch ($typeInt) { case IMG_GIF: $imageType = 'image/gif'; break; case IMG_JPG: $imageType = 'image/jpg'; break; case IMG_JPEG: $imageType = 'image/jpeg'; break; case IMG_PNG: $imageType = 'image/png'; break; case IMG_WBMP: $imageType = 'image/wbmp'; break; case IMG_XPM: $imageType = 'image/xpm'; break; default: $imageType = 'unknown'; } $mime->addHTMLImage($file_path, $imageType); } } //attachments if (is_array($email_attachments)) { foreach ($email_attachments as $attachments) { $filename = str_replace('uploads/', '', $attachments); $attachment = ''; $file_path = ''; $type = ''; if (strpos($filename, '.png') !== false) { $type .= 'image/png'; } // ADD attachment(s) $attachment1 .= "--$boundary1\r\n"; $attachment1 .= "Content-Type: $type; name=\"$filename\"\r\n"; $attachment1 .= "Content-Transfer-Encoding: base64\r\n"; $attachment1 .= "Content-Disposition: attachment; filename=\"$filename\"\r\n"; $attachment1 .= "\r\n\r\n"; $attachment1 .= $attachment; $attachment1 .= "\r\n\r\n"; $body .= $attachment1; $mime->addAttachment($file_path, $type); } } // always call these methods in this order $mime_params = array( 'text_encoding' => '7bit', 'text_charset' => '"UTF-8"', 'html_charset' => '"UTF-8"', 'head_charset' => '"UTF-8"' ); //$body = $mime->get(array('text_encoding' => '8bit','html_encoding' => '8bit')); $body = $mime->get($mime_params); $headers = $mime->headers($headers); $smtp_params = array ('host' => $smtp_hostname, 'port' => $port, 'auth' => true, // Note 1 'username' => $username, 'password' => $password); $smtp = Mail::factory('smtp', $smtp_params); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Email has been sent!</p>"); $response = array("success"=>$success); echo json_encode($response); } } }
Do you know why the images wont show up on yahoo and gmail when I send the images as attachment?
I have checked on the image path and i have put the correct image path so it should work fine.
Any advice would be much appreciated. Thanks in advance.
Edited June 5, 2020 by mark107 This topic has been moved to Installation on Linux. http://www.phpfreaks.com/forums/index.php?topic=343589.0 Hi, I have a script that creates an email through cpanel, that part works. But i am getting error reading the email. Code: [Select] Warning: imap_open() [function.imap-open]: Couldn't open stream {mail.spamarchon.com:143} in /home/spamarch/public_html/index.php on line 71here is the code: Code: [Select] $mbox = imap_open("{mail.$edomain:143}", "$euser@$edomain", "$epass"); any idea Thanks I'm working on a member modification page that works off of the javascript "onblur" method. Ideally the way I want it to work is when a person leaves the field they were in the second php script runs and returns to the page a value to the page. Right now it does just that with one problem - it won't run the attached script twice if the values are the same twice. For instance: If I'm tabbing through the fields several times for whatever reason and accidentally add an "a" to the name field one of those times, i realize this and want to go back to fix it. After I've fixed it I tab out and what should happen is the script runs, the new info is written to the databse, and the script returns new info for the page. What is currently happening is nothing - it doesn't seem to run the script. Using Chrome I see that it's executing the script but it isn't writing back to the page or updating the database. Any help or pointers I could get would be very welcome. Thanks! Scripts Below and attached: Member Edit Page: <?php $title = "TAPCO File Upload Data"; $top1 = "<!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=UTF-8' /> <title>"; $top2 = "</title> <link href='css.css' rel='stylesheet' type='text/css' /> <script type='text/javascript'> function attach_file( p_script_url ) { // create new script element, set its relative URL, and load it script = document.createElement( 'script' ); script.src = p_script_url; document.getElementsByTagName( 'head' )[0].appendChild( script ); } </script> </head> <body>"; $host="localhost"; // Host name $username="ftpuploads"; // Mysql username $password="password"; // Mysql password $db_name="ftpuploads"; // Database name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $unam = $_GET["unam"]; $q = "select * from members where username = '".$unam."'"; $r = mysql_query($q); $name = mysql_result($r, 0, 'name'); $email = mysql_result($r, 0, 'email'); $sp = mysql_result($r, 0, 'sp'); $sno = mysql_result($r, 0, 'sno'); $snow = "Sales Number: ".str_pad(mysql_result($r, 0, 'sno'), 3, 0, STR_PAD_LEFT); $fa = mysql_result($r, 0, 'fa'); $user = mysql_result($r, 0, 'user'); $admin = mysql_result($r, 0, 'admin'); $active = mysql_result($r, 0, 'active'); mysql_close(); if ($user == "0" && $admin == "1") { $disuoa = "Admin"; } elseif ($user == "1" && $admin == "0") { $disuoa = "User"; } else { die("Something is wrong, both admin and user have the same value"); } if ($active == "1") { $disactive = "Active"; } else { $disactive = "Inactive"; } if ($sp == "0") { $spcell = "<option value='1'>Yes</option> <option value='0' selected>No</option>"; } else { $spcell = "<option value='1' selected>Yes</option> <option value='0'>No</option>"; } if ($fa == "0") { $facell = "<option value='1'>Yes</option> <option value='0' selected>No</option>"; } else { $facell = "<option value='1' selected>Yes</option> <option value='0'>No</option>"; } if ($user == "0" && $admin == "1") { $uoacell = "<option value='User'>User</option> <option value='Admin' selected>Admin</option>"; } else { $uoacell = "<option value='User' selected>User</option> <option value='Admin'>Admin</option>"; } if ($active == "0") { $actcell = "<option value='1'>Yes</option> <option value='0' selected>No</option>"; } else { $actcell = "<option value='1' selected>Yes</option> <option value='0'>No</option>"; } echo $top1.$title.$top2; echo "<span id='disname'>".$name."</span><br /> <span id='disuname'>".$unam."</span><br /> <span id='disemail'>".$email."</span><br /> <br /><span id='dissno'>".$snow."</span><br /> <br /><span id='disuoa'>".$disuoa."</span><br /> <br /><span id='disactive'>".$disactive."</span><br /><br />"; echo "<form> <table> <tr> <td> Name </td> <td> Password </td> <td> Sales Person? </td> <td> Sales Number </td> <td> Full Access? </td> <td> User or Admin? </td> <td> Active? </td> </tr> <tr> <td> <input type='text' name='name' value='".$name."' onblur=\"javascript:attach_file('updatefield.php?span=disname&unam=".$unam."&fchan=name&val='+this.value)\" /> </td> <td> <span id='passres'><a href=\"javascript:attach_file('resetpassword.php?uname=".$unam."&email=".$email."')\">Reset and Send</a></span> </td> <td> <select name='sp' onblur=\"javascript:attach_file('updatefield.php?span=&unam=".$unam."&fchan=sp&val='+this.value, this.value)\"> ".$spcell." </select> </td> <td> <input type='text' name='sno' onblur=\"javascript:attach_file('updatefield.php?span=dissno&unam=".$unam."&fchan=sno&val='+this.value)\" /> </td> <td> <select name='fa'> ".$facell." </select> </td> <td> <select name='uoa'> ".$uoacell." </select> </td> <td> <select name='active'> ".$actcell." </select> </td> </table> </form> "; ?> updatefield page: <? $host="localhost"; // Host name $username="ftpuploads"; // Mysql username $password="password"; // Mysql password $db_name="ftpuploads"; // Database name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); header( 'Content-Type: text/javascript' ); $span = $_GET['span']; $username = $_GET['unam']; $fchan = $_GET['fchan']; $val = $_GET['val']; $q = "select ".$fchan." from members where username = '".$username."'"; $r = mysql_query($q); $fchanOrVal = mysql_result($r, 0, name); if ($fchanOrVal == $val) { die(); } else { $qu = "update members set ".$fchan." = '".$val."' where username = '".$username."'"; $ru = mysql_query($qu); echo "if ('".$span."' != '') { fchan_span_obj = document.getElementById( '".$span."' ); fchan_span_obj.innerHTML = '".$val."'; } else if ('".$span."' == '') { }"; } mysql_close(); ?> Hi guys I have created these codes below, uploadform.php Code: [Select] <html> <head> </head> <body> <form action="upload.php" method="post" enctype="multipart/form-data"> <table> <tr> <td><div align="left">Submit photo </div></td> <td><div align="left"> <input type="file" name="file" id="file" /> </div></td> </tr> <tr> <td><div align="left"></div></td> <td><div align="left"> <input type="submit" name="Submit" value="Submit" /> </div></td> </tr> </table> </form> </body> </html> upload.php Code: [Select] <?php /************************ * Upload file *************************/ if (isset($_POST['Submit'])) { //if "email" is filled out, send email /*** Upload File ***/ if($_FILES["file"]["size"] < 20000) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { //echo "Upload: " . $_FILES["file"]["name"] . "<br />"; //echo "Type: " . $_FILES["file"]["type"] . "<br />"; //echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; //echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { //$_FILES["file"]["name"] // Do nothing... } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); $url = "http://asiamodeltalent.com/php/mt/" . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } /************************ * Insert path and filename to array *************************/ $fname = $_FILES["file"]["name"]; $files = array("$fname"); /************************ * Send Message to email *************************/ $to = "iridion_us@yahoo.com"; $from = "contact@coder9.com"; $subject ="Email File"; $message = "Test email with file attached.\n"; $headers = "From: $from"; // boundary $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // headers for attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; // multipart boundary $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; $message .= "--{$mime_boundary}\n"; // preparing attachments $pathupload = "http://coder9.com/php/mt/" . "upload/"; for($x=0;$x<count($files);$x++){ //$file = fopen($files[$x],"rb"); $file = fopen($url[$x], "rb"); //$data = fread($file,filesize($files[$x])); $data = fread($file, filesize($url[$x])); fclose($file); $data = chunk_split(base64_encode($data)); $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$files[$x]\"\n" . "Content-Disposition: attachment;\n" . " filename=\"$files[$x]\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; $message .= "--{$mime_boundary}\n"; } // send $ok = @mail($to, $subject, $message, $headers); if ($ok) { echo "<p>mail sent to $to!</p>"; } else { echo "<p>mail could not be sent!</p>"; } } ?> The problem with this codes is the file is attached but it's empty. By the way if you want to test it you need a sub directory of /upload What is the cause of this problem? Thanks in advanced. Code works when...
<script type="text/javascript"> var currenttime = '<?php print gmdate('F d, Y H:i:s', time() + (1 * 60 * 60))?>' var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December") var serverdate=new Date(currenttime) function padlength(what){ return (what.toString().length==1)? "0"+what : what } function displaytime(){ serverdate.setSeconds(serverdate.getSeconds()+1) var datestring=montharray[serverdate.getMonth()]+" "+padlength(serverdate.getDate())+", "+serverdate.getFullYear() var timestring=padlength(serverdate.getHours())+":"+padlength(serverdate.getMinutes())+":"+padlength(serverdate.getSeconds()) document.getElementById("servertime").innerHTML=datestring+" "+timestring } window.onload=function(){ setInterval("displaytime()", 1000) } </script>Code not works when... <script type="text/javascript" src="clock.js">I want to use second option. Any help? Dear Forum, I have a problem that is getting the best of me due to the fact that it is hard to replicate and therefor hard to 'capture' in it's act. As I am not sure what the root cause is I apologize if this thread is posted in the wrong section. My possible guilty components are (PHP, Apache, MySQL, Mozilla Portable). Anyone that might have experienced what I experience and can help me to crack this one will be rewarded. Problem/Symptom: I have a application that stores data from a form in a GUI. This data is stored in the MySQL dB in individual columns and 95% of the data as serialized form. During the records life time it is uploaded from a Laptop to a central dB. This is where the problem starts. Sometimes (happens ones in around every 1000 records) the data when it is viewed on the central server have been contaminated with data from other records. On the only event I have examined the data was correct on the Laptop before upload even after upload which indicates that the contamination happened on the central level. Another finding was that part of the contaminated data came from a record that was uploaded two records later (in accordance with record ID numbering) then the contaminated record itself indicating that it has not happened during the transaction itself but at a later stage. Suspected Root Cause: In the beginning of the applications history the system had a record toggle functionality. When using this functionality and using the application with Mozilla Portable what was displayed in cash lost synchronization with MySQL and contamination occurred (this happened if toggling back and forward to fast). This was at the point in time a know bug/weakness in Mozilla Portable and was later corrected. After upgrading this part of the application the problem disappeared. (before it could be easily replicated). I cannot replicate this contamination and wonder if it still might be related to Mozilla Portable or if anyone else have experienced something similar? Happy to financially reward anyone that can help crack this one. Thank you for your time!
I am trying to implement this for two days now but stuck with logics ! Please help. Hello one and all, Just a quick request here, I've written a script that sends an email with an attached file by the user. (docx, txt, pdf, doc, rtf) are the formats I have accepted. At the moment I'm sending them with the following... Code: [Select] $fileatt_type = "application/pdf"; // File Type It works fine with all formats in older email clients, i.e, like yahoo before they updated the layout, but in the newer versions it's specific and if I try to send it this way it is always delivered as a .PDF and doesn't open if it is any of the other formats. It may sound silly but I've searched a fair bit for the other extensions or formats to include instead of the above code (maybe something like application/doc or something) but there doesn't seem to be a list. Can anyone point me in the right direction? Much obliged, PHP the learned. I need Delete Duplicate Email Records That Are Attached To One Account But Can Be Found In Multiple Accounts I have a table, consumer_mgmt. It collects consumer information from various forms. These forms are available through different pages that are part of a business package. A business can offer these signups to gather names and emails from consumers for various types of specials they may offer. So a consumer my be in the consumer_mgmt table 5, 10, 15 times for that particular business. But, that consumer may be in the consumer_mgmt table multiple times for a different business. So multiple times for multiple businesses. I need to remove duplicates for each business account so the consumer is only the consumer_mgmt only once for each business. There are approximately 15,000 rows currently in the consumer_mgmt table. I'm not sure where to begin on the logic. Since there are multiple business accounts that the emails are attached to, would one have to build a case for each loop? Hello,
I recently posted here about an issue I was having with my database orientated products page.
I have now run into another problem where say if, /db.php was typed or /db.php?p=IDoNotExist was typed, it returns blank.
I have in my code the desired content to be displayed, but it just doesn't seem to want to make a show.
I was also wondering if it is possible to show different content for whatever the URL is, so for no parameter, the content about the products, and a non existent one, maybe "Product not found"?
Here is my code:
<?php $db=mysql_connect ("localhost", "webwibco_charlie", "Hello123") or die ('I cannot connect to the database because: ' . mysql_error()); $mydb=mysql_select_db("webwibco_products"); include("header.php"); $status = htmlspecialchars( @$_GET ['p'] ); if ($status == "floorpuzzles") { echo "<h1>Our Floor Puzzles</h1>"; $sql="SELECT ID, Name, Tags, Description, Category FROM products WHERE Category LIKE '%" . FloorPuzzles . "%'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; echo "<div class=\"box\">"; echo "<h1>$Name</h1>"; echo "<div class=\"floorbox\"><a href=\"?p=$ID\"><img src=\"images/products/catalogue/big/floorpuzzles/$ID.jpg\" class=\"small\"></a></div>"; echo "<h2>$Description</h2>"; echo "</div>"; } ?> <? }else{ if ($status == $_GET["p"]) { $sql="SELECT ID, Name, Tags, Description, Pieces, Size, Barcode, Category FROM products WHERE ID = '" . $_GET['p'] . "'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $Name =$row['Name']; $ID =$row['ID']; $Description =$row['Description']; $Pieces =$row['Pieces']; $Size =$row['Size']; $Barcode =$row['Barcode']; echo "<div class=\"1\">"; echo "<h1>$Name</h1>"; echo "<div class=\"bigbox\">"; echo "<div class=\"floorbox\"><img src=\"images/products/catalogue/big/floorpuzzles/$ID.jpg\" class=\"big\"></div>"; echo "</div>"; echo "</div>"; echo "<div class=\"2\">"; echo "<p>Puzzle Pieces: $Pieces</p> <p>Puzzle Size: $Size</p> <p>Barcode: $Barcode</p>"; echo "</div>"; } }else{ ?> <? echo"<h1>Our Products</h1> <p>Our jigsaw puzzles are hand cut by skilled craftsmen and therefore each one is unique with self-correcting pieces. There is a strict quality control process at all stages by our highly experienced staff. The puzzles are durable and provide fun and excitement, enhancing learning and a child’s development.<p> <p>All of our jigsaws are made using materials from sustainable resources grown in managed forests. Where possible we support companies in the UK and source our components locally, most of our suppliers are in the East Midlands, many in Derbyshire and Nottinghamshire. We keep packaging to a minimum and take our environmental and ethical responsibilities very seriously.</p> <p>Reducing waste and recycling was a way of life for us before it became fashionable. We are constantly searching for new ideas and consult teachers when developing our jigsaws, which are often used within the national curriculum.</p> <p>As well as making our own range, we manufacture for leading suppliers to the education market. Check for \"Made in Britain\" and it is probably made by us.</p> <p>We have a wide variety of products available for viewing, from classic floor puzzles to innovative inset trays. You can take a look at all our products on this page, simply use the navigation buttons to your left.</p>"; }} include("footer.php"); ?>The final echo is what I wish to be displayed on the URL without or with an invalid parameter. Here is my site URL: http://www.webwib.co...saws/search.php (note that only the "Floor Puzzles" category has content within it). Thank you in advance for assistance. I have this script from http://lampload.com/...,view.download/ (I am not using a database) I can upload images fine, I can view files, but I want to delete them. When I press the delete button, nothing happens
http://www.jayg.co.u...oad_gallery.php
<form>
<?php $dir = dirname(__FILENAME__)."/images/gallery" ; $files1 = scandir($dir); foreach($files1 as $file){ if(strlen($file) >=3){ $foil = strstr($file, 'jpg'); // As of PHP 5.3.0 $foil = $file; $pos = strpos($file, 'css'); if ($foil==true){ echo '<input type="checkbox" name="filenames[]" value="'.$foil.'" />'; echo "<img width='130' height='38' src='images/gallery/$file' /><br/>"; // for live host //echo "<img width='130' height='38' src='/ABOOK/SORTING/gallery-dynamic/images/gallery/ $file' /><br/>"; } } }?> <input type="submit" name="mysubmit2" value="Delete"> </form>
any ideas please?
thanks
Ok, I have a GD image that is then rewrote as a png. My question is, is it possible to find out what site is requesting the image and then use it on the php image. Example, if I didn't want a domain to use my images, could I somehow me able to restirict that site? Hey every i'm just trying to change my 'Read More' text after a blog post on my site into am image. Got some code that lets me change the actual text to something else, just can't find how to change the text into an image. Code: [Select] add_filter( 'the_content_more_link', 'child_content_more_link', 10, 2 ); function child_content_more_link( $more_link, $more_link_text ) { return str_replace( $more_link_text, 'my new read more text', $more_link ); } Thanks, Matty44m Hi guys I just want to know something. With php you can handle excel files by saving them as .csv files. Then the php script reads it line by line, and commas separating the fields. But is it possible that I can insert an image (small jpg or png) file in one of these fields...and then handle the image in the php script? Just for intrest I inserted an image in excel worksheet and it did not insert it into a cell, it float. Is there maybe another to insert it in the cell and then control it with php?? Thanx in advance I'm trying to Embed the images from Apple into my PHP file. Code: [Select] $phpobj = unserialize($response); if (is_array($phpobj)) { foreach ($phpobj['value']['items'] AS $key => $val) { printf("<div><p><a href=%s>%s</a></p><p>%s</p>\n", $val['link'], $val['title'], $val['description']); } } But the problem is that the image attribute is inside a Table and using something lile $val['img'] is not working. So anybody can help me with this. Here is the RSS feed format from which I'm importing Code: [Select] <item> <title>Dead Awake - Trailer</title> <link>http://trailers.apple.com/trailers/independent/deadawake/</link> <description>DEAD AWAKE is a seductive supernatural thriller starring Rose McGowan, Amy Smart and Nick Stahl set against the backdrop of a mysterious tragedy that shattered their lives a decade ago and which sets them on a path to uncover the truth that lies between the living and the dead.</description> <pubDate>Wed, 01 Dec 2010 00:00:00 PST</pubDate> <content:encoded><![CDATA[ <table> <tr valign="top"> <td width="67"><a href="http://trailers.apple.com/trailers/independent/deadawake/"><img src="http://trailers.apple.com/trailers/independent/deadawake/images/poster.jpg" width="65" height="97" border="0"></a></td> <td> </td> <td><a href="http://trailers.apple.com/trailers/independent/deadawake/"><span style="font-size: 16px; font-weight: 900; text-decoration: underline;">Dead Awake - Trailer</span></a><br /> <span style="font-size: 12px;">DEAD AWAKE is a seductive supernatural thriller starring Rose McGowan, Amy Smart and Nick Stahl set against the backdrop of a mysterious tragedy that shattered their lives a decade ago and which sets them on a path to uncover the truth that lies between the living and the dead.<br /><b>Directed by:</b> Omar Naim<br /><b>Starring:</b> Nick Stahl, Rose McGowan, Amy Smart, Ben Marten, Kim Grimaldi, Brian Lynner, Justin Marxen, James Serpento, Jack Mishler, Shane Simmons, Rachel Storey, Justin Urich, Andrea Leon, Livia Milano, Phyllis Mumford</span></td> </tr> </table> ]]></content:encoded> </item> Ok I have finally got rid of my syntax errors with this upload script. Now im getting the error uploading your image. My folders are called project_files and project_thumbs. This is my script <?php $results = ""; error_reporting(E_ALL); ini_set("display_errors", 1); //Auto Thumbnail Function function create_thumbnail($source,$destination, $thumb_width) { $size = getimagesize($source); $width = $size[0]; $height = $size[1]; $x = 0; $y = 0; if($width> $height) { $x = ceil(($width - $height) / 2 ); $width = $height; } elseif($height> $width) { $y = ceil(($height - $width) / 2); $height = $width; } $new_image = imagecreatetruecolor($thumb_width,$thumb_width) or die('Cannot initialize new GD image stream'); $extension = get_image_extension($source); if($extension=='jpg' || $extension=='jpeg') $image = imagecreatefromjpeg($source); if($extension=='gif') $image = imagecreatefromgif($source); if($extension=='png') $image = imagecreatefrompng($source); imagecopyresampled($new_image,$image,0,0,$x,$y,$thumb_width, $thumb_width,$width,$height); if($extension=='jpg' || $extension=='jpeg') imagejpeg($new_image,$destination); if($extension=='gif') imagegif($new_image,$destination); if($extension=='png') imagepng($new_image,$destination); } //Get Extension Function function get_image_extension($name) { $name = strtolower($name); $i = strrpos($name,"."); if (!$i) { return ""; } $l = strlen($name) - $i; $extension = substr($name,$i+1,$l); return $extension; } //Random Name Function function random_name($length) { $characters = "abcdefghijklmnopqrstuvwxyz01234567890"; $name = ""; for ($i = 0; $i < $length; $i++) { $name .= $characters[mt_rand(0, strlen($characters) - 1)]; } return "image-".$name; } $images_location = "/project_files/"; $thumbs_location = "/project_thumbs/"; $thumb_width = "100"; $maximum_size = "5000000"; //Check And Save Image if($_POST) { if($_FILES['image']['name'] == ""){ $results = "Please select the image you would like to upload by clicking browse"; } else{ $size=filesize($_FILES['image']['tmp_name']); $filename = stripslashes($_FILES['image']['name']); $extension = get_image_extension($filename); if($size > $maximum_size) { $results = "Your file size exceeds the maximum file size!"; } else if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { $results = "Only the following extensions are allowed. 'jpg', 'jpeg', 'png', 'gif'."; } else { $image_random_name=random_name(15).".".$extension; $copy = @copy($_FILES['image']['tmp_name'], $images_location.$image_random_name); if (!$copy) { $results = "Error while uploadin your image! Please try again!"; } else{ create_thumbnail($images_location.$image_random_name,$thumbs_location.$image_random_name, $thumb_width); $results = "Your image has been uploaded!"; } } } } ?> and the form Code: [Select] <html> <head> <title>test</title> </head> <body> <?php echo $results; ?> <form action="#" method="post" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="5000000" /> <input type="file" name="image" /> <input type="submit" value="Upload Image" /> </form> </body> </html> I have a site where I need to have lets call it image1 displayed, then I want to change this image based on a php if statement, for instance: if $var == $var2 change the image ....blah blah so I was also going to have the names of my images stored in my database, i.e. image1.jpg and image2.jpg in my database. the image is in its own div tag set as the background image of the div tag if that makes any diference. Thanks Hi guys, i have a form that uploads a school photo. All i want to do is resize the image to its widest dimension of a width of 480 px and then obviously constrain the height. can anyone help me, ive tried to do this myself but when it comes to image properties i really struggle etc. heres my upload code. Code: [Select] <?php include("includes/connection.php"); // Where the file is going to be placed $schoolimage = "SchoolImages/"; //This path will be stored in the database as it does not contain the filename $currentdir = getcwd(); $path = $currentdir . '/' . $schoolimage; // Get the schoolid for the image and school linker table $schoolid = $_POST['schoolid']; //Get the school name $query = "SELECT * FROM school WHERE school_id = ".$schoolid; $result = mysql_query($query) or die("Error getting school details"); $row = mysql_fetch_assoc($result); $schoolname = $row['name']; //Use this path to store the path of the file in the database. $filepath = $schoolimage . $schoolname; //Create the folder if it does not already exist if(!file_exists('SchoolImages')) { if(mkdir('SchoolImages')) { echo 'Folder ' . 'SchoolImages' . ' created.'; } else { echo 'Error creating folder ' . 'SchoolImages'; } } //Store the folder for the course title. if(!file_exists( $filepath )) { if(mkdir( $filepath )) { echo 'Folder ' . $schoolname . ' created.'; } else { echo 'Error creating folder ' . $schoolname; } } // Where the file is going to be placed $target_path = $filepath; // Add the original filename to our target path. Result is "uploads/filename.extension" echo $target_path = $target_path . '/' . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name'])." has been uploaded"; $filename = $_FILES['uploadedfile']['name']; //Store the filename, path other criteria in the database echo $query = "INSERT INTO image(image_id, name, path) VALUES(0, '$filename', '$filepath')"; //Perform the query $add = mysql_query($query, $conn) or die("Unable to add the image details to the database"); $imageid = mysql_insert_id(); //Store the filename, path other criteria in the database echo $query = "INSERT INTO image_school( image_id, school_id ) VALUES('$imageid', '$schoolid')"; //Perform the query $add = mysql_query($query, $conn) or die("Unable to add the image details to the database"); $message = 'Upload Successful'; } else { $message = 'There was an error uploading the file, please try again!'; } //Close the connection to the database mysql_close($conn); header("Location: add_school_photo_form.php? message={$message}&schoolid={$schoolid}"); //header("Location: add_school_photo_form.php? message=$message, schoolid=$schoolid"); exit(); ?> Id be eternially gratefull. Kind Regards Dean Hello all I have a requirement to create images mostly made up of rectangles circles and squares etc I have discovered imageline but is there anything a bit more exspansive? |