+ Almost all quality improvement comes via simplification of design, manufacturing... layout, processes, and procedures.

September 7, 2008, 10:21 am

php 5 and imagecreatefromjpeg() recoverable error: Premature end of JPEG file

March 17, 2008

Ok I recently came up with a problem creating thumbnails for a project I am working on. I was stumped for hours, it seems that some files that were saved from a mac or certain photo editing programs would cause php to not recognize it a jpg thus giving the error:  

imagecreatefromjpeg() : gd-jpeg, libjpeg: recoverable error: Premature end of JPEG

After researching this problem I realized it was a problem with php 5 and gd2. Heres how to fix it

  • php 4 : No action neccesarry it should work fine
  • php 5.0 - 5.1.2 = Upgrade to the latest php 5
  • php 5.1.3 - current = Declare this variable in your file before calling imagecreatefromjpeg()   

ini_set(’gd.jpeg_ignore_warning’, 1);

Doing that will cause gd2,php to ignore the error and continue where it use to just fail and do nothing.

Posted by Anthony LeBoeuf under PHP | Comments (8)

Cubecart custom category order

August 5, 2007

So I developed another new mod for cubecart, this one allows you to sort out your categories in cubecart the way you want without staying with the normal sort by name or id as seen in other mods. This mod only modifies 3 files and installs one column “pos” to your database to do the ordering. Remember to back up your database and files before attempting any modification on your original files. To download this file click on the link below.

Custom category ordering 1.0

custom_category_order_1.3 (updated for manual ordering)

Posted by Anthony LeBoeuf under Cubecart, PHP | Comments (8)

Cubecart multiple delete and re categorize admin hack

July 15, 2007

I am developing a new shopping cart using the cubecart system, the client has about 2500 parts in the database. After importing these products into the database I noticed that a good 500 were mis categorized and about 100 were out of date and had to be removed. Cubecart didnt have any support for multi re-categorize or multiple deletes so I created the following hack. This hack will allow you to check off all the products on the product view page and do 2 different things. Either delete the selected products or move the selected products to a different category. To enable this hack in your cubecart admin panel paste the code in the following areas .

Due to people not being able to copy the code correctly I have pasted it in a text file which can be viewed here
install_multi_delete_recat.txt

You can also download my own index.php with the mod already installed, this will work perfect for you if you havent already modded your admin/products/index.php. Download that file here: install_multi_delete_recat-2.zip

Posted by Anthony LeBoeuf under Cubecart, mysql, PHP | Comments (0)

mysql update from another table

July 3, 2007

Recently I needed to update a bunch of rows in mysql with information from another table. I will explain how to do this simple process.

  1. Open up phpmyadmin or similar database editor
  2. view the sql query below
Code (sql)
  1.  
  2. UPDATE updatefrom p, updateto pp
  3. SET pp.last_name = p.last_name
  4. WHERE pp.visid = p.id

Lets say we have 2 tables one named main and one named updateto and one named updatefrom, In the first line we assign variables to these t tables (p and pp) from there we can call column names using this format table.columname. If we had first_name and last_name in both tables and wanted to update the “updateto” table with the info from “updatefrom” this is how you would write it.

Posted by Anthony LeBoeuf under mysql, Web Technology, PHP | Comments (1)

Dynamic PHP Email Forms without massive amounts of code

May 19, 2007

Ever had a HUGE form that just emails basic information and just thought to yourself, damn there has to be an easier way to do this! I’ve got a solution that will work, basicly what it does is takes the form loops all the input fields and sends them through email (or proccess them any way you would like) I’ll go over the basics here.

First we need a form Lets start with something simple

Code (html)
  1. <form method="post" action="process.php">
  2. Name:   
  3. <input name="Name" />
  4. Email:   
  5. <input name="Email" />
  6. Address:   
  7. <input name="Address" />
  8. <input name="Address" type="submit" />
  9. </form>

Now to process it, first we will import all variables and send them through a loop

Code (php)
  1.  
  2.  
  3.  
  4. $server = $_SERVER[‘HTTP_HOST’];   
  5.  
  6. foreach($_POST as $key => $data) {
  7.   if($key != ‘required’) {
  8.       if($data !=) {
  9.           $message .= ‘<strong>’.$key.‘</strong>: ‘.$data.;
  10.       }
  11.   }
  12. }

Now you can display your information if you wish or go further to send it with an email, im using a email class i built which you can download here.

Code (php)
  1.  
  2.  
  3. echo
  4. <p style="margin: 20px; background-color: #f2fced; border: #cccccc 1px solid; padding: 20px"> </p>
  5.  
  6. <h4>Your forum Has been sucessfully sent with the following information</h4>
  7. .$message.‘ 
  8.  
  9. ;   
  10.  
  11. $m = new Mail(); // create the mail
  12. $m->From( "email@server.com" );
  13. $m->To( "email@server.com"  );
  14. $m->Subject( ‘New forum submission from  ‘.$server.‘ Contact Page’ );
  15. $m->Body( $message);
  16. $m->Priority(4);   
  17.  
  18. $m->Send(); // send the mail

This method is very easy for sending simple forms where serverside validation is not needed. Check it out play with it and post if you have any questions ill be happy to help!

Posted by Anthony LeBoeuf under PHP | Comments (1)