phpbrew is a helpful too to run multiple versions of php. Why run multiple versions of php? In this case it was required for upgrading an old legacy site that depended on php 5.2. Phpbrew.
Tag Archives: php
PHP Namespaces Explained
PHP Namespaces Explained | Dayle Rees.
Recompiling PHP5 With Bundled Support for GD on Ubuntu – CuMu.Li
Link
Recompiling PHP5 With Bundled Support for GD on Ubuntu – CuMu.Li
This helped me resolve the Drupal error when setting up a local development environment.
Automatically use remote or local images in Zen-Cart. Contribution:Web images – Zen Cart(tm) Wiki
Link
Automatically use remote or local images in Zen-Cart. Contribution:Web images – Zen Cart(tm) Wiki
For my showcase application I wanted to show images directly linked from an external site and not only store them on the local server; nevertheless both methods are working.
I changed the database field length to accept longer names and I may now enter a Products_image like http://www.siteurl.com/images/externalimage.jpg.
I have changed some code and the result may be seen at rcmarket.net.
Changes:
includesfunctionshtml_output.php line 165:
//by rl if image is located on the web, strip any local path
if (strstr($src, 'http') != '0') {
$src = strstr($src, 'http://');
}
// use old method on template images by rl: test for http
if (strstr($src, 'includes/templates') or strstr($src, 'includes/languages') or PROPORTIONAL_IMAGES_STATUS == '0' or strstr($src, 'http') != '0' ) {
return zen_image_OLD($src, $alt, $width, $height, $parameters);
}
includesmodulespagespopup_imageheader_php.php line 45:
//by rl if start of path = http then link to external site's image, only small image may have a http address
$imagepath = DIR_WS_IMAGES;
if (substr($products_image,0,4) == 'http') {
$imagepath ='';
}
includesmodulesfeatured_products.php line 52:
//by rl if start of path = http then link to external site's image
//replace DIR_WS_IMAGES with variable $imagepath
$imagepath = DIR_WS_IMAGES;
if (substr($listing->fields['products_image'],0,4) == 'http') {
$imagepath ='';
}
$list_box_contents[$row][$col] = array('params' =>'class="centerBoxContentsFeatured centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
'text' => '<a href="' . zen_href_link(zen_get_info_page($featured_products->fields['products_id']), 'products_id=' . $featured_products->fields['products_id']) . '">' . zen_image($imagepath . $featured_products->fields['products_image'], $featured_products->fields['products_name'], IMAGE_FEATURED_PRODUCTS_LISTING_WIDTH, IMAGE_FEATURED_PRODUCTS_LISTING_HEIGHT) . '</a>
<a href="' . zen_href_link(zen_get_info_page($featured_products->fields['products_id']), 'products_id=' . $featured_products->fields['products_id']) . '">' . $featured_products->fields['products_name'] . '</a>
' . $products_price);
includesmodulesnew_products.php line 56:
similar to above
includesmodulesproduct_listing.php line 162:
//by rl if start of path = http then link to external site's image
$imagepath = DIR_WS_IMAGES;
if (substr($listing->fields['products_image'],0,4) == 'http') {
$imagepath =''; }
if (isset($_GET['manufacturers_id'])) {
$lc_text = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'products_id=' . $listing->fields['products_id']) . '">' . zen_image($imagepath . $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTH, IMAGE_PRODUCT_LISTING_HEIGHT, 'class="listingProductImage"') . '</a>';
} else {
$lc_text = '<a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), ($_GET['cPath'] > 0 ? 'cPath=' . $_GET['cPath'] . '&' : ) . 'products_id=' . $listing->fields['products_id']) . '">' . zen_image($imagepath . $listing->fields['products_image'], $listing->fields['products_name'], IMAGE_PRODUCT_LISTING_WIDTH, IMAGE_PRODUCT_LISTING_HEIGHT, 'class="listingProductImage"') . '</a>';
}
break;
includesmodulesspecials_index.php line 51:
//by rl if start of path = http then link to external site's image
$imagepath = DIR_WS_IMAGES;
if (substr($specials_index->fields['products_image'],0,4) == 'http') {
$imagepath ='';
}
$products_price = zen_get_products_display_price($specials_index->fields['products_id']);
$specials_index->fields['products_name'] = zen_get_products_name($specials_index->fields['products_id']);
$list_box_contents[$row][$col] = array('params' => 'class="centerBoxContentsSpecials centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
'text' => '<a href="' . zen_href_link(zen_get_info_page($specials_index->fields['products_id']), 'products_id=' . (int)$specials_index->fields['products_id']) . '">' . zen_image($imagepath . $specials_index->fields['products_image'], $specials_index->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a>
<a href="' . zen_href_link(zen_get_info_page($specials_index->fields['products_id']), 'products_id=' . $specials_index->fields['products_id']) . '">' . $specials_index->fields['products_name'] . '</a>
' . $products_price);
includestemplatestemplate_defaultpopup_image_additionaltpl_main_page.php line 19:
//by rl if start of path = http then link to external site's image
$imagepath = DIR_WS_IMAGES;
if (substr($listing->fields['products_image'],0,4) == 'http') {
$imagepath ='';
}
echo '<a href="javascript:window.close()">' . zen_image($imagepath . $products_image, $products_values->fields['products_name'] . ' ' . TEXT_CLOSE_WINDOW) . '</a>';
}
includestemplatestemplate_defaultsideboxestpl_reviews_random.php line 10:
//by rl if start of path = http then link to external site’s image
$imagepath = DIR_WS_IMAGES;
if (substr($random_product->fields['products_image'],0,4) == 'http') {
$imagepath =''; }
$content = "";
$content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent centeredContent">';
$content .= '<a href="' . zen_href_link(FILENAME_PRODUCT_REVIEWS_INFO, 'products_id=' . $random_review_sidebox_product->fields['products_id'] . '&reviews_id=' . $random_review_sidebox_product->fields['reviews_id']) . '">' . zen_image($imagepath . $random_review_sidebox_product->fields['products_image'], $random_review_sidebox_product->fields['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '
' . $review_box_text . ' ..</a>
' . zen_image(DIR_WS_TEMPLATE_IMAGES . 'stars_' . $random_review_sidebox_product->fields['reviews_rating'] . '.gif' , sprintf(BOX_REVIEWS_TEXT_OF_5_STARS, $random_review_sidebox_product->fields['reviews_rating']));
$content .= '</div>';
Basically you assign the constant DIR_WS_IMAGES to a variable $imagepath.
Then add the short method to check if the image starts with http.
If it does up then set imagepath to blank. else use DIR_WS_IMAGES.
You must also insert $imagepath in place of DIR_WS_IMAGES in the zen_image function calls.
In addition to these files a number of other files need
to be updated. All products, featured, new, cart, listing, product info and maybe others.
Make sure to pay attention to the file product being referenced
for example:
$featured_product->fields['products_image']
$new_product->fields['products_image']
$listing->fields['products_image']
etc.
The shopping cart also must be updated.
Delete files with PHP: unlink – Manual
Link
Delete files with PHP: unlink – Manual
Example of deleting a file and a directory with PHP:
$fh = fopen('test.html', 'a');
fwrite($fh, 'Hello world!
’);
fclose($fh);
mkdir(‘testdir’, 0777);
unlink(‘test.html’);
unlink(‘testdir’);
Also: how to list a directory of files:
function list_files($dir)
{
if(is_dir($dir))
{
if($handle = opendir($dir))
{
while(($file = readdir($handle)) !== false)
{
if($file != "." && $file != ".." && $file != "Thumbs.db"/*pesky windows, images..*/)
{
echo ''.$file.'
'."n";
}
}
closedir($handle);
}
}
}
/*
To use:
list_files("images/");
*/
redirect after login depending on role | drupal.org
Link
redirect after login depending on role | drupal.org
global $user; if (in_array('Script Team',$user->roles)) $path = 'admin/user/user'; elseif (in_array('Patient',$user->roles)) $path = 'node/99'; elseif (in_array('Admin',$user->roles)) $path = 'admin'; else $path = 'user'; return $path;
For use in the login destination module http://drupal.org/project/login_destination
Download file with php and curl
This is a great tutorial on using cURL in php and downloading a file. http://phpsense.com/php/php-curl-functions.html I was able to download a zip file to my web server from a website using this code. Sample code: ————- <?php /*** Initialize the … Continue reading