mrkeck Sharing the Love

22Apr/130

Enable Pear Packages on Hostgator

  1. cPanel for Hostgator
  2. PHP PEAR Packages
  3. Search "package you want"
  4. Click "Install"
Filed under: hostGator, PHP No Comments
9Mar/130

PHP HTML img src BLOB

echo "<img src='data:image/jpeg;base64, " . base64_encode(your BLOB) . "'>"
Filed under: HTML, PHP No Comments
7Mar/130

PHP Get Directory Above Web Root

dirname($_SERVER['DOCUMENT_ROOT'])
Filed under: PHP No Comments
4Mar/130

PHP GD jpg too large

This one had me stumped for a while. I am using WAMP, but has nothing to do with the issue.

I was trying to manipulate a jpg that was 1.3MB, which I was sure was not too large. However, that is the compressed size. Once it is loaded into GD it is no longer compressed. In order to calculate the uncompressed size, multiply the pixel width times pixel height times 4 (conversion rate from pixels to bytes)

(w x h x 4)

Make sure the memory_limit in php.ini is large enough to handle the load

Example

Assume sample jpg is 1.3MB and has width of 2,500 pixels and height of 5,000 pixels
(2500 x 5000 x 4)=50,000,000 (50MB)

Filed under: GD, PHP No Comments
2Feb/131

PHP exec not working on Mac using MAMP

Fixed:
Open /Applications/MAMP/Library/bin/envvars

Comment out the following lines:

DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH

That's it

Filed under: MAMP, PHP 1 Comment
20Dec/120

PHP csv Not Recognizing Line End on Mac

//Fix mac line ending issue
ini_set("auto_detect_line_endings", true);
 
//put each line of the file into an array element
$lines = file('theFile.csv');

If I make the csv in Windows it works without the ini_set, but if I make it on a Mac, not so much...so I am going to set it in the php.ini when I do new setups, but for a quick fix ini_set

Filed under: mac, PHP No Comments
15Dec/120

Comment Out a Portion of Code Convention

if(0){  //Change 0 to 1 to turn on code segment
     //Code that I want to turn on and off
}
15Dec/120

PHP Redirect To Root of Current Folder

<?php
header('location: .');
?>
Filed under: PHP No Comments
12Nov/120

PHP access network drive

I'm using WAMP and I can't get PHP to access B:/ which is mapped to \\10.10.30.125\images\

However,
It has no problem accessing //10.10.30.125/images/ (PHP is cool with'/' and don't have to worry about escaping) so use that instead, and just use the B drive as an easy way to check on it.

Filed under: PHP No Comments
5Oct/120

PHP file_get_contents timing out even with set_time_limit

It turns out that file_get_contents looks at max_input_time. So I changed max_input_time=180 in php.ini and set set_time_limit(0) in the page I was working on. All good now.

Filed under: PHP No Comments