article

Thursday, July 15, 2010

php - Upload image from url

php - Upload image from url















<?
error_reporting(E_ALL);

// define the filename extensions
define('ALLOWED_FILENAMES', 'jpg|jpeg|gif|png');
// define a directory
define('IMAGE_DIR', 'image');

// check against a regexp for an actual http url and for a valid filename,
$url = "http://www.philwebcreative.com/philweb_logo.jpg";
if(!preg_match('#^http://.*([^/]+\.('.ALLOWED_FILENAMES.'))$#', $url, $m)) {
die('Invalid url given');
}

// try getting the image
if(!$img = file_get_contents($url)) {
die('Getting that file failed');
}

// try writing the file with the original filename
if(!$f = fopen(IMAGE_DIR.'/'.$m[1], 'w')) {
die('Opening file for writing failed');
}

if (fwrite($f, $img) === FALSE) {
die('Could not write to the file');
}

fclose($f);
?>


Wednesday, July 14, 2010

Resize images on the fly

Resize images on the fly

Follow these steps:

1. Get the script and save it on your computer

Once done, you can display images like this:






<img src="/scripts/timthumb.php?src=/images/whatever.jpg&h=150&w=150&zc=1" alt="" />



Demo

http://creativedesign-mind.com/r-ednalan/demo/resize_onthefily.php

Saturday, July 10, 2010

Integrate WordPress Blog into CakePHP Application

Integrate WordPress Blog into CakePHP Application

INSTALL WORDPRESS IN CAKEPHP
1. Install wordpress under the webroot
==app\webroot\blog
2. added htacess in the root
==htaccess file in main CakePHP folder(root).

RewriteEngine on
RedirectMatch temp ^/blog/wp-admin$ http://www.example.com/blog/wp-admin/
RewriteRule blog$ /blog/ [L] RewriteRule blog/wp-admin$ /blog/wp-admin/ [L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]


3. login wordpress admin
4. set up the the permalinks under Setting category menu then permalink
6. choose Custom Structure then enter this value
/%postname%/
7. above is the url blog
www.example.com/blog/Top-Firefox-Plugins-for-Web-Development

Related Post