Jump to content

drisate

Members
  • Posts

    805
  • Joined

  • Last visited

Everything posted by drisate

  1. tried this one as well ... same result ... wtf am i doing wrong the stupid image has transparancy but looses it when it's resized ... <?php imageAntiAlias($outImg,true); imagealphablending($outImg, false); imagesavealpha($outImg,true); $transparent = imagecolorallocatealpha($outImg, 255, 255, 255, 0); for($x=0;$x<$outWidth;$x++) { for($y=0;$y<$outHeight;$y++) { imageSetPixel( $outImg, $x, $y, $transparent ); } } // Resize image imagecopyresampled($outImg, $srcImg, 0, 0, 0, 0, $outWidth, $outHeight, $srcWidth, $srcHeight); ?>
  2. tryed this <?php imagealphablending($outImg, false); $color = imagecolortransparent($outImg, imagecolorallocatealpha($outImg, 0, 0, 0, 127)); imagefill($outImg, 0, 0, $color); imagesavealpha($outImg, true); // Resize image imagecopyresampled($outImg, $srcImg, 0, 0, 0, 0, $outWidth, $outHeight, $srcWidth, $srcHeight); ?> Not working ... Tryed this: <?php imagecolortransparent($outImg, imagecolorallocate($outImg, 0, 0, 0)); imagealphablending($outImg, false); imagesavealpha($outImg, true); // Resize image imagecopyresampled($outImg, $srcImg, 0, 0, 0, 0, $outWidth, $outHeight, $srcWidth, $srcHeight); ?> still not working ...
  3. I think i got some if it mixed up a bit ... but it's still not working ... any help would be apreciated This version should have some of the error solved but the background is still black <?php // Constants $CACHE_DIR = "media/original"; function diewith($msg) { header("HTTP/1.0 500 Internal error."); echo $msg; die; } // Get params $uri = $_REQUEST['uri'] or diewith("missing 'uri' argument."); $inWidth = $_REQUEST['w']; $inHeight = $_REQUEST['h']; $method=$_REQUEST['method']; // Handle client cache (304) $srcTime = @filemtime($uri) or diewith("Unable to open 'uri'"); $reqTimeStr = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']); // Browser cache version not too old ? if ((! empty($reqTimeStr)) and ($srcTime <= strtotime($reqTimeStr))) { // End the request with status 304 header("HTTP/1.1 304 Not modified"); exit; } else { // Set the last change in HTTP reponse header("Last-Modified: " . date('r', $srcTime)); } // Get actual size of source image $imgInfo = getimagesize($uri) or diewith("Unable to open '$uri'"); $srcWidth = $imgInfo[0]; $srcHeight = $imgInfo[1]; $srcType = $imgInfo[2]; switch($srcType) { case 1 : $srcType = "gif"; break; case 2 : $srcType = "jpeg"; break; case 3 : $srcType = "png"; break; default: $srcType = "???"; } // Compute the size wanted if ($method == "stretch") { // Exact size $outWidth = $inWidth; $outHeight = $inHeight; } else { /* Default : 'fit' */ // Max size : resize $xRatio = ($inWidth) ? ($srcWidth / $inWidth) : 0; $yRatio = ($inHeight) ? ($srcHeight / $inHeight): 0; $ratio = max($xRatio, $yRatio, 1); $outWidth = intval($srcWidth / $ratio); $outHeight = intval($srcHeight/ $ratio); } // Compute name of cache image $cacheName = md5($uri).'-'.basename($uri).'#'.$outWidth.'x'.$outHeight; $cacheFile = dirname(__FILE__) . '/'. $CACHE_DIR . '/' . $cacheName; // If cache doesn't exist or too old, build it. if (!file_exists($cacheFile) or ($srcTime > filectime($cacheFile))) { if ($imgInfo[0]<$outWidth){$outWidth=$imgInfo[0];} if ($imgInfo[1]<$outHeight){$outHeight=$imgInfo[1];} // Create output image $outImg = imagecreatetruecolor ($outWidth, $outHeight); // Load src image switch($srcType) { case "png": $srcImg = imagecreatefrompng($uri); break; case "gif": $srcImg = imagecreatefromgif($uri); break; case "jpeg": $srcImg = imagecreatefromjpeg($uri); break; default: diewith("unsupported file type '$uri'"); }; imagealphablending($outImg, false); $color = imagecolorallocatealpha($outImg, 0, 0, 0, 127); imagefill($outImg, 0, 0, $color); imagesavealpha($outImg, true); // Resize image imagecopyresampled($outImg, $srcImg, 0, 0, 0, 0, $outWidth, $outHeight, $srcWidth, $srcHeight); // Save to cached thumb switch($srcType) { case "png": $res = imagepng($outImg, $cacheFile); break; case "gif": $res = imagegif($outImg, $cacheFile); break; case "jpeg": $res = imagejpeg($outImg, $cacheFile); break; default: diewith("unsupported file type '$uri'"); } // Check result if (!$res) diewith("Unable to save thumb to '$cacheFile'. Check the access right of the HTTP server."); } // HTTP Header header("Content-Type:image/$srcType"); // Dump cache file readfile($cacheFile) or diewith("Unable to open cached thumb '$cacheFile'"); ?>
  4. Bumb ... anybody? i tryed this and it's still not working ... Full script looks like <?php // Constants $CACHE_DIR = "media/original"; function diewith($msg) { header("HTTP/1.0 500 Internal error."); echo $msg; die; } // Get params $uri = $_REQUEST['uri'] or diewith("missing 'uri' argument."); $inWidth = $_REQUEST['w']; $inHeight = $_REQUEST['h']; $method=$_REQUEST['method']; // Handle client cache (304) $srcTime = @filemtime($uri) or diewith("Unable to open 'uri'"); $reqTimeStr = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']); // Browser cache version not too old ? if ((! empty($reqTimeStr)) and ($srcTime <= strtotime($reqTimeStr))) { // End the request with status 304 header("HTTP/1.1 304 Not modified"); exit; } else { // Set the last change in HTTP reponse header("Last-Modified: " . date('r', $srcTime)); } // Get actual size of source image $imgInfo = getimagesize($uri) or diewith("Unable to open '$uri'"); $srcWidth = $imgInfo[0]; $srcHeight = $imgInfo[1]; $srcType = $imgInfo[2]; switch($srcType) { case 1 : $srcType = "gif"; break; case 2 : $srcType = "jpeg"; break; case 3 : $srcType = "png"; break; default: $srcType = "???"; } // Compute the size wanted if ($method == "stretch") { // Exact size $outWidth = $inWidth; $outHeight = $inHeight; } else { /* Default : 'fit' */ // Max size : resize $xRatio = ($inWidth) ? ($srcWidth / $inWidth) : 0; $yRatio = ($inHeight) ? ($srcHeight / $inHeight): 0; $ratio = max($xRatio, $yRatio, 1); $outWidth = intval($srcWidth / $ratio); $outHeight = intval($srcHeight/ $ratio); } // Compute name of cache image $cacheName = md5($uri).'-'.basename($uri).'#'.$outWidth.'x'.$outHeight; $cacheFile = dirname(__FILE__) . '/'. $CACHE_DIR . '/' . $cacheName; // If cache doesn't exist or too old, build it. if (!file_exists($cacheFile) or ($srcTime > filectime($cacheFile))) { if ($imgInfo[0]<$outWidth){$outWidth=$imgInfo[0];} if ($imgInfo[1]<$outHeight){$outHeight=$imgInfo[1];} // Create output image $outImg = imagecreatetruecolor ($outWidth, $outHeight); // Load src image switch($srcType) { case "png": $srcImg = imagecreatefrompng($uri); imagealphablending($srcImg, false); $color = imagecolorallocatealpha($srcImg, 0, 0, 0, 127); imagefill($srcImg, 0, 0, $color); imagesavealpha($srcImg, true); break; case "gif": $srcImg = imagecreatefromgif($uri); break; case "jpeg": $srcImg = imagecreatefromjpeg($uri); break; default: diewith("unsupported file type '$uri'"); }; // Resize image imagecopyresampled($outImg, $srcImg, 0, 0, 0, 0, $outWidth, $outHeight, $srcWidth, $srcHeight); // Save to cached thumb switch($srcType) { case "png": $res = imagepng($outImg, $cacheFile); break; case "gif": $res = imagegif($outImg, $cacheFile); break; case "jpeg": $res = imagejpeg($outImg, $cacheFile); break; default: diewith("unsupported file type '$uri'"); } // Check result if (!$res) diewith("Unable to save thumb to '$cacheFile'. Check the access right of the HTTP server."); } // HTTP Header header("Content-Type:image/$srcType"); // Dump cache file readfile($cacheFile) or diewith("Unable to open cached thumb '$cacheFile'"); ?> You can see it in action here: http://youproud.com/new/thumbs.php?uri=media/original/47002-amour.png&w=19&h=&method=fit Or Here using the htaccess redirection http://youproud.com/new/media/original/47002-amour.png~19 original image here http://youproud.com/new/media/original/47002-amour.png As you can see the original image has transparancy
  5. Hey guys i am currently working on a thumbnail script. The idea is to be able to resize any image on the fly by adding some parameters to the images url ex: thisimage.jpg~160x160 It's then picked up by an htaccess rule that sends it to a php script that resize the image and returns it using the GD library. The script is working great but got a problem keeping the transparency with PNG images ... What ever i do the resized image has a black background. I tryed all sorts of things but it's just not working ... can anybody help me understand where i got it wrong? // [......] // Create output image $outImg = imagecreate ($outWidth, $outHeight); // Load src image switch($srcType) { case "png": $srcImg = imagecreatefrompng($uri); $background = imagecolorallocate($srcImg, 255, 255, 255); imagecolortransparent($srcImg, $background); imagealphablending($srcImg, true); imagesavealpha($srcImg, true); break; case "gif": $srcImg = imagecreatefromgif($uri); break; case "jpeg": $srcImg = imagecreatefromjpeg($uri); break; default: diewith("unsupported file type '$uri'"); }; // Resize image imagecopyresampled($outImg, $srcImg, 0, 0, 0, 0, $outWidth, $outHeight, $srcWidth, $srcHeight); // [......]
  6. thanks but unfortunatly i get the same result <?php // ... // Compute name of cache image $cacheName = md5($uri).'-'.basename($uri).'#'.$outWidth.'x'.$outHeight; $cacheFile = dirname(__FILE__) . '/'. $CACHE_DIR . '/' . $cacheName; // If cache doesn't exist or too old, build it. if (!file_exists($cacheFile) or ($srcTime > filectime($cacheFile))) { if ($imgInfo[0]<$outWidth){$outWidth=$imgInfo[0];} if ($imgInfo[1]<$outHeight){$outHeight=$imgInfo[1];} // Create output image $outImg = imagecreate ($outWidth, $outHeight); // Load src image switch($srcType) { case "png": $srcImg = imagecreatefrompng($uri); $background = imagecolorallocate($srcImg, 255, 255, 255); imagecolortransparent($srcImg, $background); imagealphablending($srcImg, true); imagesavealpha($srcImg, true); break; case "gif": $srcImg = imagecreatefromgif($uri); break; case "jpeg": $srcImg = imagecreatefromjpeg($uri); break; default: diewith("unsupported file type '$uri'"); }; // Resize image imagecopyresampled($outImg, $srcImg, 0, 0, 0, 0, $outWidth, $outHeight, $srcWidth, $srcHeight); // Save to cached thumb switch($srcType) { case "png": $res = imagepng($outImg, $cacheFile); break; case "gif": $res = imagegif($outImg, $cacheFile); break; case "jpeg": $res = imagejpeg($outImg, $cacheFile); break; default: diewith("unsupported file type '$uri'"); } // Check result if (!$res) diewith("Unable to save thumb to '$cacheFile'. Check the access right of the HTTP server."); } // HTTP Header header("Content-Type:image/$srcType"); // Dump cache file readfile($cacheFile) or diewith("Unable to open cached thumb '$cacheFile'"); ?>
  7. Hey guys i have a script that create thumnail version of any JPG, PNG, GIF images. It works great but the only problem is it's not keeping the transparency. It adds a black background instead. I made a very big search and tryed at least 100 things and i keep gething the black background ... This is the original image with the transparancy: This is the image after it's passed in the thumnail script: <?php // ... // Create output image $outImg = imagecreatetruecolor ($outWidth, $outHeight); // Load src image switch($srcType) { case "png": $srcImg = imagecreatefrompng($uri); $background = imagecolorallocate($srcImg, 255, 255, 255); imagecolortransparent($srcImg, $background); imagealphablending($srcImg, true); imagesavealpha($srcImg, true); break; case "gif": $srcImg = imagecreatefromgif($uri); break; case "jpeg": $srcImg = imagecreatefromjpeg($uri); break; default: diewith("unsupported file type '$uri'"); }; // Resize image imagecopyresampled($outImg, $srcImg, 0, 0, 0, 0, $outWidth, $outHeight, $srcWidth, $srcHeight); // Save to cached thumb switch($srcType) { case "png": $res = imagepng($outImg, $cacheFile); break; case "gif": $res = imagegif($outImg, $cacheFile); break; case "jpeg": $res = imagejpeg($outImg, $cacheFile); break; default: diewith("unsupported file type '$uri'"); } //... ?>
  8. drisate

    Thumb

    I tryed case "png": $srcImg = imagecreatefrompng($uri); imagealphablending($srcImg,false); imagesavealpha($srcImg,true); break; but i keep gething black background images Ex:
  9. You can check if the http:// string exist and add it if not if (!strstr($string, "http://") ) {echo "http://";} echo $string;
  10. drisate

    Thumb

    Hey guys i need help with the PNG in this code ... how can i keep the transparency? // Constants $CACHE_DIR = "media/original"; function diewith($msg) { header("HTTP/1.0 500 Internal error."); echo $msg; die; } // Get params $uri = $_REQUEST['uri'] or diewith("missing 'uri' argument."); $inWidth = $_REQUEST['w']; $inHeight = $_REQUEST['h']; $method=$_REQUEST['method']; // Handle client cache (304) $srcTime = filemtime($uri) or diewith("Unable to open 'uri'"); $reqTimeStr = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']); // Browser cache version not too old ? if ((! empty($reqTimeStr)) and ($srcTime <= strtotime($reqTimeStr))) { // End the request with status 304 header("HTTP/1.1 304 Not modified"); exit; } else { // Set the last change in HTTP reponse header("Last-Modified: " . date('r', $srcTime)); } // Get actual size of source image $imgInfo = getimagesize($uri) or diewith("Unable to open '$uri'"); $srcWidth = $imgInfo[0]; $srcHeight = $imgInfo[1]; $srcType = $imgInfo[2]; switch($srcType) { case 1 : $srcType = "gif"; break; case 2 : $srcType = "jpeg"; break; case 3 : $srcType = "png"; break; default: $srcType = "???"; } // Compute the size wanted if ($method == "stretch") { // Exact size $outWidth = $inWidth; $outHeight = $inHeight; } else { /* Default : 'fit' */ // Max size : resize $xRatio = ($inWidth) ? ($srcWidth / $inWidth) : 0; $yRatio = ($inHeight) ? ($srcHeight / $inHeight): 0; $ratio = max($xRatio, $yRatio, 1); $outWidth = intval($srcWidth / $ratio); $outHeight = intval($srcHeight/ $ratio); } // Compute name of cache image $cacheName = md5($uri).'-'.basename($uri).'#'.$outWidth.'x'.$outHeight; $cacheFile = dirname(__FILE__) . '/'. $CACHE_DIR . '/' . $cacheName; // If cache doesn't exist or too old, build it. if (!file_exists($cacheFile) or ($srcTime > filectime($cacheFile))) { if ($imgInfo[0]<$outWidth){$outWidth=$imgInfo[0];} if ($imgInfo[1]<$outHeight){$outHeight=$imgInfo[1];} // Create output image $outImg = imagecreatetruecolor ($outWidth, $outHeight); // Load src image switch($srcType) { case "png": $srcImg = imagecreatefrompng($uri); break; case "gif": $srcImg = imagecreatefromgif($uri); break; case "jpeg": $srcImg = imagecreatefromjpeg($uri); break; default: diewith("unsupported file type '$uri'"); }; // Resize image imagecopyresampled($outImg, $srcImg, 0, 0, 0, 0, $outWidth, $outHeight, $srcWidth, $srcHeight); // Save to cached thumb switch($srcType) { case "png": $res = imagepng($outImg, $cacheFile); break; case "gif": $res = imagegif($outImg, $cacheFile); break; case "jpeg": $res = imagejpeg($outImg, $cacheFile); break; default: diewith("unsupported file type '$uri'"); } // Check result if (!$res) diewith("Unable to save thumb to '$cacheFile'. Check the access right of the HTTP server."); } // HTTP Header header("Content-Type:image/$srcType"); // Dump cache file readfile($cacheFile) or diewith("Unable to open cached thumb '$cacheFile'");
  11. Hey guys i created a search engin on my website and i need to filter out the result by relevance ... So fare my code looks like this: if ($_GET[q]){ // On sépare le nom et le prénom $arr = explode (' ', $_GET[q]); $where .= "("; foreach($arr as $mot){ if ($_GET[type]=='1'){ $where .= "evenement.occ like '%$mot%' or evenement.description like '%$mot%' or "; }else{ $where .= "membre.nom like '%$mot%' or membre.prenom like '%$mot%' or "; } } $where = substr($where, 0, -3); $where .= ")"; } if ($_GET[eve_categ]){ if ($where){ $where .= " and ("; }else{ $where .= " ("; } foreach ($_GET[eve_categ] as $key => $value){ $eve_categ .= "-$value-"; $where .="evenement.eve_categ = '$value' or "; } $where = substr($where, 0, -3).') and evenement.user_id=membre.id'; } if ($where==""){$where='1=1';} if ($_GET[type]=='1'){ $select = mysql_query("SELECT * FROM membre, evenement WHERE $where and membre.id=evenement.user_id limit $offset,$nombre_par_page"); }else{ $select = mysql_query("SELECT * FROM membre WHERE $where limit $offset,$nombre_par_page"); } while ($recherche = mysql_fetch_array($select)) { // [...]
  12. i tryed a new file size function and now i am back to the same result i had by using the php filesize function ... i don't get it thought ... theres no way there is 60 GB of MP3 when the total used space on the server is 34 GB ... function sizeFormat($size) { $sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB"); if ($size == 0) { return('n/a'); } else { return (round($size/pow(1024, ($i = floor(log($size, 1024)))), 2) . $sizes[$i]); } } function getSize($file) { $size = filesize($file); if ($size < 0) if (!(strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')) $size = trim(`stat -c%s $file`); else{ $fsobj = new COM("Scripting.FileSystemObject"); $f = $fsobj->GetFile($file); $size = $file->Size; } return $size; } function getFileSizeByExtension($path, $extensions=array()){ $ignore = array('.', '..', '.htaccess'); foreach($extensions as $ext){ $totalsize[$ext]['size'] = 0; // file size in bytes $totalsize[$ext]['count'] = 0; // file counter } if ($handle = opendir ($path)){ while (false !== ($file = readdir($handle))){ $nextpath = $path . '/' . $file; if (!in_array($file, $ignore)){ $nextpath_ext = pathinfo($nextpath, PATHINFO_EXTENSION); if (is_dir ($nextpath)){ $result = getFileSizeByExtension($nextpath, $extensions); foreach($result as $ext => $data){ $totalsize[$ext]['size'] += $data['size']; $totalsize[$ext]['count'] += $data['count']; } } elseif (is_file ($nextpath) && in_array($nextpath_ext, $extensions)){ $totalsize[$nextpath_ext]['size'] += getSize ($nextpath); $totalsize[$nextpath_ext]['count']++; } } } } closedir ($handle); return $totalsize; }
  13. I tryed changing the filesize function to this one function fsize($file) { // filesize will only return the lower 32 bits of // the file's size! Make it unsigned. $fmod = filesize($file); if ($fmod < 0) $fmod += 2.0 * (PHP_INT_MAX + 1); // find the upper 32 bits $i = 0; $myfile = fopen($file, "r"); // feof has undefined behaviour for big files. // after we hit the eof with fseek, // fread may not be able to detect the eof, // but it also can't read bytes, so use it as an // indicator. while (strlen(fread($myfile, 1)) === 1) { fseek($myfile, PHP_INT_MAX, SEEK_CUR); $i++; } fclose($myfile); // $i is a multiplier for PHP_INT_MAX byte blocks. // return to the last multiple of 4, as filesize has modulo of 4 GB (lower 32 bits) if ($i % 2 == 1) $i--; // add the lower 32 bit to our PHP_INT_MAX multiplier return ((float)($i) * (PHP_INT_MAX + 1)) + $fmod; } But now the page takes for ever to load ... It's been loading for 13 minutes now ... and it keeps loading lol
  14. Thanks wildteen88 :-) It's working great for jpg, png and gif but for some reasons when it gets to mp3 it goes off the chart ... it outputs 61 GB... Cpanel is repporting that the hole domain (MySQL included) uses only 34 GB Array ( [jpg] => Array ( [size] => 98127430 [count] => 5140 ) [png] => Array ( [size] => 1450028 [count] => 326 ) [gif] => Array ( [size] => 1026727 [count] => 137 ) [mp3] => Array ( [size] => 64418466742 [count] => 9831 ) )
  15. Hey guys i need to create a function that scans the whole website and gets the total used size for each extenssion inside an array to then be able to use it this way <?php echo 'Total space used for MP3 '.$scan[mp3][size].' bytes'; echo 'Total space used for JPG '.$scan[jpg][size].' bytes'; echo 'Total space used for PHP '.$scan[code=php:0][size].' bytes'; /// [...] ?>
  16. Why don't you just read the RSS feeds?
  17. Juste a fast look and your using the var $password in your code $password = check_input($_POST['password']); But $pass un your MySQL querry. Was that an error?
  18. You can explode the dot and keep only the number part <?php // 1. item number 1 $explode = explode ('.', $number); echo $explode[0]; // 1 echo $explode[1]; // item number 1 ?>
  19. Indeed ... i forgot the check box are set as an array ... hmm then i guess you need to do it like this <?php session_start(); $DB_HOST = "localhost"; $DB_USERNAME = ""; $DB_PASSWORD = ""; $DB_NAME = ""; $DB = mysql_connect("$DB_HOST", "$DB_USERNAME", "$DB_PASSWORD") or die('DB Error: ' . mysql_error()); mysql_select_db($DB_NAME); if ($_SESSION[username]){ if ($_GET[message_id]){ $message = mysql_fetch_array(mysql_query("SELECT * FROM messages WHERE id='$_GET[message_id]' and recipient='$_SESSION[username]'")); } if ($_GET[mod]=="post"){ if ($_POST[user]){ foreach ($_POST[user] as $key => $value){ $content = $_POST['content']; $subject = $_POST['subject']; $query ="INSERT INTO messages (title, content, recipient, from1) VALUES ('$subject', '$content', '$value','$_SESSION[username]')"; mysql_query($query) or die('Error, query failed'); } } ?> <form id="form_id" name="myform" method="post"> <p>Subject: <label for="subject"></label> <input type="text" name="subject" id="subject" <?php if ($message[subject]){echo 'value="RE: '.$message[subject].'"';} ?> /> </p> <?php if (!$_GET[message_id]){ ?> <script type="text/javascript"> <!-- var formblock; var forminputs; function prepare() { formblock= document.getElementById('form_id'); forminputs = formblock.getElementsByTagName('input'); } function select_all(name, value) { for (i = 0; i < forminputs.length; i++) { // regex here to check name attribute var regex = new RegExp(name, "i"); if (regex.test(forminputs[i].getAttribute('name'))) { if (value == '1') { forminputs[i].checked = true; } else { forminputs[i].checked = false; } } } } if (window.addEventListener) { window.addEventListener("load", prepare, false); } else if (window.attachEvent) { window.attachEvent("onload", prepare) } else if (document.getElementById) { window.onload = prepare; } //--> </script> <?php $select = mysql_query("SELECT * FROM members") or die(mysql_error()); while ($member = mysql_fetch_array($select)) { echo '<input type="checkbox" name="user[]" value="'.$member[name].'">'.$member[name].'<br>'; } ?> <br><br><a href="#" onClick="select_all('user', '1');">Check All Locations</a> | <a href="#" onClick="select_all('user', '0');">Uncheck All Locations</a><br><br> <? } ?> <p> <label for="content">Content:</label> <textarea name="content" id="content" cols="45" rows="5"></textarea> <input type="hidden" name="user[]" id="from" value='<?php echo $message[from]; ?>' /> </p> <p> <input type="submit" name="submit" id="submit" value="Post" /> </p> </form> <?php }elseif ($_GET[mod]=="see"){ echo "FROM: $message[from]<br>TO: $message[recipient]<br>SUBJECT: $message[subject]<hr>$message[content]<hr><a href='?mod=post&message_id=$message[id]'>REPLY</a>"; }else{ echo "<a href='?mod=post'>COMPOSE</a><hr>"; $select = mysql_query("SELECT * FROM messages WHERE recipient='$_SESSION[username]'") or die(mysql_error()); while ($messages = mysql_fetch_array($select)) { echo "<a href='?mod=see&message_id=$messages[id]'>[$messages[from]] $messages[subject]</a><br>"; } } }else{ echo "You are not connected. Please login first."; } ?> The script, form and check buttons changed. works fine now i tested it.
  20. The code above has everything in it See messages Post message Reply message I added to it the check all and uncheck button I think you got all you need ... have fun. I am out ;-)
  21. it would look like <?php session_start(); $DB_HOST = "localhost"; $DB_USERNAME = ""; $DB_PASSWORD = ""; $DB_NAME = ""; $DB = mysql_connect("$DB_HOST", "$DB_USERNAME", "$DB_PASSWORD") or die('DB Error: ' . mysql_error()); mysql_select_db($DB_NAME); if ($_SESSION[username]){ if ($_GET[message_id]){ $message = mysql_fetch_array(mysql_query("SELECT * FROM messages WHERE id='$_GET[message_id]' and recipient='$_SESSION[username]'")); } if ($_GET[mod]=="post"){ if ($_POST[user]){ foreach ($_POST[user] as $key => $value){ $content = $_POST['content']; $subject = $_POST['subject']; $query ="INSERT INTO messages (title, content, recipient, from1) VALUES ('$subject', '$content', '$value','$_SESSION[username]')"; mysql_query($query) or die('Error, query failed'); } } ?> <form id="form1" name="form1" method="post"> <p>Subject: <label for="subject"></label> <input type="text" name="subject" id="subject" <?php if ($message[subject]){echo 'value="RE: '.$message[subject].'"';} ?> /> </p> <?php if (!$_GET[message_id]){ ?> <SCRIPT LANGUAGE="JavaScript"> <!-- function checkAll(field) { for (i = 0; i < field.length; i++) field[i].checked = true ; } function uncheckAll(field) { for (i = 0; i < field.length; i++) field[i].checked = false ; } --> </script> <?php $select = mysql_query("SELECT * FROM members") or die(mysql_error()); while ($member = mysql_fetch_array($select)) { echo '<input type="checkbox" name="user[]" value="'.$member[name].'">'.$member[name].'<br>'; } ?> <br> <input type="button" name="CheckAll" value="Check All" onClick="checkAll(document.form1.user)"> <input type="button" name="UnCheckAll" value="Uncheck All" onClick="uncheckAll(document.form1.user)"> <? } ?> <p> <label for="content">Content:</label> <textarea name="content" id="content" cols="45" rows="5"></textarea> <input type="hidden" name="user[]" id="from" value='<?php echo $message[from]; ?>' /> </p> <p> <input type="submit" name="submit" id="submit" value="Post" /> </p> </form> <?php }elseif ($_GET[mod]=="see"){ echo "FROM: $message[from]<br>TO: $message[recipient]<br>SUBJECT: $message[subject]<hr>$message[content]<hr><a href='?mod=post&message_id=$message[id]'>REPLY</a>"; }else{ echo "<a href='?mod=post'>COMPOSE</a><hr>"; $select = mysql_query("SELECT * FROM messages WHERE recipient='$_SESSION[username]'") or die(mysql_error()); while ($messages = mysql_fetch_array($select)) { echo "<a href='?mod=see&message_id=$messages[id]'>[$messages[from]] $messages[subject]</a><br>"; } } }else{ echo "You are not connected. Please login first."; } ?>
  22. The hole thing would look like this (I did not test the code) <?php session_start(); $DB_HOST = "localhost"; $DB_USERNAME = ""; $DB_PASSWORD = ""; $DB_NAME = ""; $DB = mysql_connect("$DB_HOST", "$DB_USERNAME", "$DB_PASSWORD") or die('DB Error: ' . mysql_error()); mysql_select_db($DB_NAME); if ($_SESSION[username]){ if ($_GET[message_id]){ $message = mysql_fetch_array(mysql_query("SELECT * FROM messages WHERE id='$_GET[message_id]' and recipient='$_SESSION[username]'")); } if ($_GET[mod]=="post"){ if ($_POST[user]){ foreach ($_POST[user] as $key => $value){ $content = $_POST['content']; $subject = $_POST['subject']; $query ="INSERT INTO messages (title, content, recipient, from1) VALUES ('$subject', '$content', '$value','$_SESSION[username]')"; mysql_query($query) or die('Error, query failed'); } } ?> <form id="form1" name="form1" method="post"> <p>Subject: <label for="subject"></label> <input type="text" name="subject" id="subject" <?php if ($message[subject]){echo 'value="RE: '.$message[subject].'"';} ?> /> </p> <?php if (!$_GET[message_id]){ $select = mysql_query("SELECT * FROM members") or die(mysql_error()); while ($member = mysql_fetch_array($select)) { echo '<input type="checkbox" name="user[]" value="'.$member[name].'">'.$member[name].'<br>'; } } ?> <p> <label for="content">Content:</label> <textarea name="content" id="content" cols="45" rows="5"></textarea> <input type="hidden" name="user[]" id="from" value='<?php echo $message[from]; ?>' /> </p> <p> <input type="submit" name="submit" id="submit" value="Post" /> </p> </form> <?php }elseif ($_GET[mod]=="see"){ echo "FROM: $message[from]<br>TO: $message[recipient]<br>SUBJECT: $message[subject]<hr>$message[content]<hr><a href='?mod=post&message_id=$message[id]'>REPLY</a>"; }else{ echo "<a href='?mod=post'>COMPOSE</a><hr>"; $select = mysql_query("SELECT * FROM messages WHERE recipient='$_SESSION[username]'") or die(mysql_error()); while ($messages = mysql_fetch_array($select)) { echo "<a href='?mod=see&message_id=$messages[id]'>[$messages[from]] $messages[subject]</a><br>"; } } }else{ echo "You are not connected. Please login first."; } ?> From that code you can add the missing pieces you need like the status of the messages and the member login systeme I still think the checkbox is not the best way of doing this ... I would of used coma seperated usernames ...
  23. You would do the form like this and use the same code as above to send your message <?php $message = mysql_fetch_array(mysql_query("SELECT * FROM messages WHERE id='$_GET[message_id]'")); ?> <form id="form1" name="form1" method="post" action="newmess.php"> <p>Subject: <label for="subject"></label> <input type="text" name="subject" id="subject" value="RE: <?=$message[subject]?>" /> </p> <p> <label for="content">Content:</label> <textarea name="content" id="content" cols="45" rows="5"></textarea> <input type="hidden" name="from" id="from" value='<?=$message[recipient]?>' /> <input type="hidden" name="user[]" id="from" value='<?=$message[from]?>' /> </p> <p> <input type="submit" name="submit" id="submit" value="Post" /> </p> </form> Just make sure you get the id of the message right
  24. Your using subject as the name of your imput not title and from not from1 <?php if ($_POST[user]){ foreach ($_POST[user] as $key => $value){ // [..] code that adds the message to the database $content = $_POST['content']; $from = $_POST['from']; $subject = $_POST['subject']; $query ="INSERT INTO messages (title, content, recipient, from1) VALUES ('$subject', '$content', '$value','$from')"; mysql_query($query) or die('Error, query failed'); } } ?>
×
×
  • 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.