Jump to content

Alex

Staff Alumni
  • Posts

    2,467
  • Joined

  • Last visited

Everything posted by Alex

  1. I see nothing wrong except that you're using $date in the string but you set $day, not $date.
  2. Next time use or [code=php:0] tags. You might also want to look into [url=http://php.net/copy]copy() [/code]
  3. I wrote a quick class for image manipulation. It's quick, so it's not the best but it'll do everything you want. I also wrote pretty good documentation for it and wrote some examples. It'll help you with the resizing at least.. Class: <?php /* @ImageClass v0.0.4 Started: 8/10/09 Last Edit: 8/24/09 By:>>Alexander Allen @Vars>> $image $image>> Image Resource $ext $ext>> Image Resource Extension $file $file>> Filename of the original image @Methods>> __construct([$im]) << Creates a new Image class instance $im>> (Optional) filename setImage($im) << Sets, or replaces the current image instance $im>> filename resize($width, $height[, $porportional=FALSE[, $percent=NULL[, $max=NULL]]]) << Resizes the current image instance $width>> New width for the image $height>> New height for the image $porportional>> (Optional) If set the image is scaled down portportionally $percent>> (Optional) This is required if $porportional is set to true. It determines the size of the new image in % (0-100) $max>> (Optional) This sets the max width or height allowed. If either is over the limit the image will be scaled down porportionally. crop($width, $height, $x, $y) << Crops the current image instance $width>> New width for the image $height>> New height for the image $x>> Determines the x start-point $y>> Determines the y start-point $position>> (Optional) When set it overrides the $x and $y positions given and crops to the set position. Valid values are: >> CENTER, CENTER_LEFT, CENTER_RIGHT, TOP_CENTER, TOP_LEFT, TOP_RIGHT, BOTTOM_CENTER, BOTTOM_LEFT, BOTTOM_RIGHT save($loc[, $compression=0]) << Saves the current image instance $loc>> The path and file name to save the image to $compression>> (Optional) Determines the compression level (Default: 0) output() << Outputs the current image instance to the browser No Parameters Additional Notes>> 8/12/09>> - Added optional position parameter to cropping. - Added output() - Changed $im parameters for __construct() and setimage(), it now takes a filename instead of a image resource - Added var $file, contains the filename of the original Image Resource - Added Example 2 8/23/09>> - Modified resize() to support setting a max size (X|Y) 8/24/09>> - Some small clean-ups / optimizations - Better Error reporting @Examples>> Example 1>> $image = new Image('test.png'); $image->resize(null, null, true, 50); $image->save('images/newimage.png'); >> This example will first create an image from the resource 'test.png'. It then resizes it porportionally to a 50% scale. Finally the image is saved to images/newimage.png. Example 2>> <?php include('image.class.php'); $image = new Image('test.gif'); $image->crop(50, 50, null, null, CENTER_LEFT); $image->output(); ?> >> This example first creates an image resource from test.gif It then crops it to a 50, 50 square using the CENTER_LEFT positioning Finally the image is output and displayed in the browser. */ class Image { var $image, $ext, $file; public function __construct($im=NULL) { define('CENTER', 0, true); define('CENTER_LEFT', 1, true); define('CENTER_RIGHT', 2, true); define('TOP_CENTER', 3, true); define('TOP_LEFT', 4, true); define('TOP_RIGHT', 5, true); define('BOTTOM_CENTER', 6, true); define('BOTTOM_LEFT', 7, true); define('BOTTOM_RIGHT', 8, true); if(empty($im)) return true; $info = @getimagesize($im); $backtrace = debug_backtrace(); if(!$info) return die('<b>Fatal error:</b> \'' . $im . '\' is not a valid image resource on <b>line ' . $backtrace[0]['line'] . ' [' . $backtrace[0]['file'] . ']</b>'); $ex = explode('/', $info['mime']); $this->ext = $ex[1]; $func = 'imagecreatefrom' . $this->ext; $this->image = @$func($im); $this->file = $im; return true; } public function setImage($im) { $info = @getimagesize($this->file); $backtrace = debug_backtrace(); if(!$info) return die('<b>Fatal error:</b> \'' . $im . '\' is not a valid image resource on <b>line ' . $backtrace[0]['line'] . ' [' . $backtrace[0]['file'] . ']</b>'); $ex = explode('/', $info['mime']); $this->ext = $ex[1]; $func = 'imagecreatefrom' . $this->ext; $this->image = @$func($im); $this->file = $im; return true; } public function resize($width, $height, $porportional=FALSE, $percent=NULL, $max=NULL) { $backtrace = debug_backtrace(); if(empty($this->image)) return die('<b>Fatal error:</b> Invalid call to Image()->resize, no image is set on <b>line ' . $backtrace[0]['line'] . ' [' . $backtrace[0]['file'] . ']</b>'); $info = Array(imagesx($this->image), imagesy($this->image)); if($porportional) { if(empty($max) && empty($percent)) return false; if(empty($max)) { $new_width = $info[0] * ($percent/100); $new_height = $info[1] * ($percent/100); } else { if($info[0] < $max && $info[1] < $max) return false; $new_width = ($info[0] > $info[1]) ? $max : ($info[0]/$info[1]) * $max; $new_height = ($info[0] > $info[1]) ? ($info[1]/$info[0]) * $max : $max; } } else { $new_width = $width; $new_height = $height; } $new_image = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $new_width, $new_height, $info[0], $info[1]); $this->image = $new_image; return true; } public function crop($width, $height, $x, $y, $position=NULL) { $backtrace = debug_backtrace(); if(empty($this->image)) return die('<b>Fatal error:</b> Invalid call to Image()->crop, no image is set on <b>line ' . $backtrace[0]['line'] . ' [' . $backtrace[0]['file'] . ']</b>'); $info = Array(imagesx($this->image), imagesy($this->image)); if($width > $info[0] || $height > $info[1]) return false; if(!empty($position) && $position >= 0 && $position <= { switch($position) { case CENTER: $x = ($info[0] - $width)/2; $y = ($info[1] - $height)/2; break; case CENTER_LEFT: $x = 0; $y = ($info[1] - $height)/2; break; case CENTER_RIGHT: $x = ($info[0] - $height); $y = ($info[1] - $height)/2; break; case TOP_CENTER: $x = ($info[0] - $width)/2; $y = 0; break; case TOP_LEFT: $x = 0; $y = 0; break; case TOP_RIGHT: $x = ($info[0] - $width); $y = 0; break; case BOTTOM_CENTER: $x = ($info[0] - $width)/2; $y = ($info[1] - $height); break; case BOTTOM_LEFT: $x = 0; $y = ($info[1] - $height); break; case BOTTOM_RIGHT: $x = ($info[0] - $width); $y = ($info[1] - $height); break; default: return false; break; } } $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this->image, 0, 0, $x, $y, $width, $height, $width, $height); $this->image = $new_image; return true; } public function save($loc, $compression=0) { $backtrace = debug_backtrace(); if(empty($this->image)) return die('<b>Fatal error:</b> Invalid call to Image()->save, no image is set on <b>line ' . $backtrace[0]['line'] . ' [' . $backtrace[0]['file'] . ']</b>'); $func = 'image' . $this->ext; return $func($this->image, $loc, $compression); } public function output() { $backtrace = debug_backtrace(); if(empty($this->image)) return die('<b>Fatal error:</b> Invalid call to Image()->output, no image is set on <b>line ' . $backtrace[0]['line'] . ' [' . $backtrace[0]['file'] . ']</b>'); header('Content-type: image/' . $this->ext); $func = 'image' . $this->ext; $func($this->image); } } For your specific case where you want to resize images to 800X600 you can do something like this: //include class $im = new Image('image..'); $im->resize(800, 600);
  4. Use cURL, you can use this function the same way you use file_get_contents. function getPage($url, $timeout=25, $header=null){ $curl = curl_init(); curl_setopt ($curl, CURLOPT_URL, $url); curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout); curl_setopt ($curl, CURLOPT_USERAGENT, sprintf("Mozilla/%d.0",rand(4,5))); curl_setopt ($curl, CURLOPT_HEADER, (int)$header); curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0); $html = curl_exec ($curl); curl_close ($curl); return $html; }
  5. It means exactly what it says.. Check the manual: split() It is indeed depreciated as of PHP 5.3.0, meaning it'll throw an E_DEPRECATED notice. You could still use it, but it'll be removed and not supported so it's best to find another method.
  6. There are no % wildcards so that query wouldn't match things like you stated..
  7. Alex

    cookies

    It should be: echo "Welcome {$_COOKIE['username']} : You have been LoggedIn";
  8. I don't think that's what he means. It sounds to me like you're trying to store the the value of $variable instead you're storing the string '$variable' it self. If I'm correct show us the code used to preform that insert into the database so we can tell you how to fix it.
  9. Depending on how many rows you're calling there shouldn't be much of a performance difference.
  10. $query isn't an object so it doesn't have any members, thus you can't use the method fetchrow() on it.
  11. Store each IP address that has clicked in a table. And when it's click make sure it's not in the table, if it's not then increment a number. $result = mysql_query("SELECT ip FROM `clicked_ips` WHERE ip='$ip'"); if(!mysql_num_rows($result)) { //Increment a number //Then Add them to the table mysql_query("INSERT into `clicked_ips` (ip) VALUES('$ip')"); } else { //Error: You have already clicked this.. }
  12. You could shorten that, just to make it look a little nicer: <?php function addX() { return (rand(1, 5) == 1) ? true : false; } ?>
  13. Any difference would be negligible.
  14. $loan = ($finance > '2000') ? $finance - 2000 : $finance; $deposit = ($finance > '2000') ? $loan : $finance / 10;
  15. You defined $whatclient, then used $whichclient in the sql statement.
  16. I find it's always good to keep things are simple as possible. The less lines the better, so although it doesn't really matter, it's probably a good idea to change something like: function SetPass($pass){ $pass = sha1($pass); $this->pass = $pass; return $this; } to: function SetPass($pass){ $this->pass = sha1($pass); return $this; } It's not going to make a performance difference or anything, it's just more organized.
  17. Please press the "Solved" Button on the bottom left of the page.
  18. $q = "SELECT pid, topic_id, LEFT(author_name, 20), author_id from ibf_posts order by pid desc limit 1";
  19. I'm not sure I understand your question completely. But just by looking at the code I'm guessing you want this: query_posts($urls[$day]); Anything inbetween single quotes will be parsed as a string. So instead of the value of $urls[$day], it would literally be the string '$urls[$day]', and you had a period in there
  20. $arr = array_slice(explode('a', $str), 0, 20);
  21. This can't be done with PHP alone. You could make it refresh periodically to update, or you could use AJAX and run something every X seconds/minutes to check if anything has changed, if so update the content.
  22. Will the things that you want non-effected be within ( )? If so you can do this: <?php $name = 'FINANCE MANAGER (FM)'; $split = explode(' ', $name); foreach($split as &$part) { $part = ($part{0} != '(') ? ucfirst(strtolower($part)) : $part; } $name = implode(' ', $split); echo $name; Output: Finance Manager (FM)
  23. You can use file_get_contents() or cURL. Since you're not posting data file_get_contents() will work fine. ex: $var = file_get_contents('http://submissions.ask.com/ping?sitemap=http://www.mysite.com/sitemap_index.xml');
  24. When you're outputting apply nl2br() to it as well.
×
×
  • 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.