473,738 Members | 5,084 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Configuring PHP with GD support

44 New Member
Hi to all,

Firstly I must state my knowledge of php is limited but I am a quick learner. I have taken on the task of finishing a friends website due to his untimely passing and have hit a problem with the completion of his work.

The site involves the uploading of a picture, jpg, png or gif. as part of an order process. The files involved are called order.php, step1.php and then step2.php.

The picture uploads to the upload folder, (called uploads), ok and step1.php is called/initiated but then fails to move to step 2. Once the picture is uploaded it is supposed to have a thumbnail produced which is to be stored in a serperate folder, called thumbs, and this is used in step2.php. The thumbnail is not being created and step2 is not called.

Some info that may be useful, is that the site has just been moved to a dedicated server. I'm not sure if this would make any difference.

It is a linux based server but then the old one was too.

The upload folders have full permissions

I have added the

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. error_reporting(E_ALL);
  4. ini_set('display_errors', True);
  5. ?> 
  6.  
  7.  
to the step1.php file and this reported the following error.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Fatal error: Call to undefined function imagecreatefromjpeg() 
  3.  
  4.  
If the file is a gif or png then the error differs in relation to the upload file type.
Here is the section of code where this line reports to.

Expand|Select|Wrap|Line Numbers
  1.  
  2. if ( (strtolower($ext)=="jpg") || (strtolower($ext)=="jpeg") ) {
  3.     $imgOriginal = imagecreatefromjpeg($storePath);
  4.  
  5. } elseif (strtolower($ext)=="gif") {
  6.     $imgOriginal = imagecreatefromgif($storePath);
  7.  
  8. } elseif (strtolower($ext)=="png") {
  9.     $imgOriginal = imagecreatefrompng($storePath);
  10.  
  11. } else {
  12.     debug("Uploaded file didn't appear to be a web safe image.");
  13.  
  14. ob_end_flush();
  15. exit(0);
  16. }
  17.  
  18.  
I am not sure if this is enough information so I will add the entire step1.php for assistance.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3. error_reporting(E_ALL);
  4. ini_set('display_errors', True);
  5. ?> 
  6.  
  7.  
  8. <?php
  9. session_start();
  10. ob_start();
  11.  
  12. // javascript was required so the user will never use the degraded version
  13. $used_degraded = false;
  14.  
  15. // my debug function. comment out the echo's to stop showing the debug text
  16. function debug($details) {
  17. if ($details != "") {
  18.  echo $details . "<br />";
  19. } else {
  20.  echo "<hr />";
  21. }
  22. }
  23.  
  24. ?>
  25.  
  26. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  27. <html xmlns="http://www.w3.org/1999/xhtml">
  28. <head>
  29.    <title>Untitled Document</title>
  30. <link href="css.css" rel="stylesheet" type="text/css" />
  31. </head>
  32.  
  33. <body>
  34. <h1>There was a problem!!</h1>
  35.  
  36. <?php
  37. if (!isset($_SESSION["uploadFilename"]) || $_SESSION["uploadFilename"] == "") { 
  38.     ?>
  39. <p>There was an error with your upload. Please go back and try again.</p>
  40. <p>&nbsp;</p>
  41.  
  42. <?php
  43. } else { 
  44.  
  45. // set up the storage folders
  46. include("paths.php");
  47.  
  48. $storeFilename = $_SESSION["uploadFilename"];
  49.  
  50. $storePath = $storeFolder . $storeFilename;
  51. $workingPath = $workingFolder . storeFilename;
  52.  
  53. debug("Uploaded filename: ". $storePath);
  54.  
  55. // resize the image so that the shortest side is 350px to send to the flash
  56. $shortestSide = 350;
  57. $imgSize = getimagesize($storePath);
  58.  
  59. // memory calculation from http://forums.devnetwork.net/viewtopic.php?t=44550
  60. $memoryNeeded = round( (($imgSize[0] * $imgSize[1] * $imgSize['bits'] * $imgSize['channels'] / 8 + Pow(2, 16)) * 1.8) );
  61.  
  62. debug("We will need ". ($memoryNeeded/1024/1024) ."MB of memory to open the image.");
  63.  
  64. //-- need to add something here that stops the script if the memory required is greater than what's allocated.
  65.  
  66. $imgWidth = $imgSize[0];
  67. $imgHeight = $imgSize[1];
  68.  
  69. debug("The original image is ". $imgWidth ."px &times; ". $imgHeight ."px.");
  70.  
  71. //-- do we have a minimum image size?
  72.  
  73. if ($imgHeight > $imgWidth) {
  74.  
  75. // height is greater than width
  76. $ratio = 1/($imgWidth/$shortestSide);
  77.  
  78. debug("It's height is greater than width.");
  79. } else {
  80.  
  81. // height is less than or equal to the width
  82. $ratio = 1/($imgHeight/$shortestSide);
  83.  
  84. debug("It's height is less than or equal to the width.");
  85.             }
  86.  
  87. debug("Resize ratio: ". number_format($ratio,3) ." (to 3 dp).");
  88.  
  89. // calculate new size
  90. $newWidth = round($imgWidth * $ratio);            
  91. $newHeight = round($imgHeight * $ratio);
  92.  
  93. debug("The new image is ". $newWidth ."px &times; ". $newHeight ."px.");
  94.  
  95. ini_set('memory_limit', (104857600*3)); // reserve 300mb of memory to resize big pictures
  96.  
  97. // resize and save the working image
  98. $ext = strtolower(end(explode('.', $storePath)));
  99. debug("File is a ". strtoupper($ext));
  100.  
  101. if ( (strtolower($ext)=="jpg") || (strtolower($ext)=="jpeg") ) {
  102. $imgOriginal = imagecreatefromjpeg($storePath);
  103.  
  104. } elseif (strtolower($ext)=="gif") {
  105. $imgOriginal = imagecreatefromgif($storePath);
  106.  
  107. } elseif (strtolower($ext)=="png") {
  108. $imgOriginal = imagecreatefrompng($storePath);
  109.  
  110. } else {
  111. debug("Uploaded file didn't appear to be a web safe image.");
  112. ob_end_flush();
  113. exit(0);
  114. }
  115.  
  116.  
  117. //I can't help but feel something is missing from here. Badvoc added comment
  118.  
  119.  
  120. $imgNew = imagecreatetruecolor($newWidth, $newHeight);
  121.  
  122. debug("If there is a fatal error below please make your image smaller and try again!");
  123.  
  124. imagecopyresampled($imgNew, $imgOriginal, 0, 0, 0, 0, $newWidth, $newHeight, $imgWidth, $imgHeight); 
  125.  
  126. ini_restore('memory_limit'); // put the memory limit back to it's default
  127.  
  128.  
  129.  
  130. if (is_writable($workingFolder)) {
  131. $done = imagejpeg($imgNew, $workingFolder . $storeFilename , 90);
  132.  
  133. if ($done == TRUE) {
  134. debug("New image saved to: " . $storeFilename);
  135. header('Location: step2.php?filename=' . $storeFilename);
  136.  
  137. //The following line was originally commented out but uncommenting has not made any difference...yet. Badvoc added comment
  138. echo '<a href="step2.php?filename='. $storeFilename .'">Continue&hellip;</a>';
  139. ?>
  140.  
  141. <?php } else { ?>
  142. <p>We weren't able to store the image on our server.</p>
  143. <?php
  144. }
  145. } else { ?>
  146. <p>The working folder isn't writable!</p>
  147. <?php }
  148.     }
  149.  
  150. ob_end_flush();
  151. ?>
  152.  
  153. </body>
  154. </html>
  155.  
  156.  
Sorry if this is a bit long but I wanted to provide everyone with as much info as possible.

Many thanks

Badvoc
Sep 9 '07 #1
44 9560
badvoc
44 New Member
Additional.

I have noticed in phpmyadmin that i have 2 warning messages. I'm not sure if they will have anything to do with my problem.


The mbstring PHP extension was not found and you seem to be using a multibyte charset. Without the mbstring extension phpMyAdmin is unable to split strings correctly and it may result in unexpected results.
and

Your PHP MySQL library version 5.0.27 differs from your MySQL server version 5.0.22. This may cause unpredictable behavior
Again many thanks
Sep 9 '07 #2
kovik
1,044 Recognized Expert Top Contributor
Yikes. That post is too long, so I didn't read all of it. I did notice that you said that you got an error stating that imagecreatefrom jpeg() doesn't exist. This means that the GD library is not properly set up.

What PHP version are you using?
Sep 9 '07 #3
badvoc
44 New Member
Yikes. That post is too long, so I didn't read all of it. I did notice that you said that you got an error stating that imagecreatefrom jpeg() doesn't exist. This means that the GD library is not properly set up.

What PHP version are you using?
Again I do apologise for the lenght. I looked into posting an image of the code but it didn't workout.

Thanks for the response though.

I have called phpinfo.php and it says php version 5.1.6.

Is this the right info you require?
Sep 9 '07 #4
kovik
1,044 Recognized Expert Top Contributor
Mmhmm.

Is this local or hosted? If it's hosted, you'll need to talk with your host about why they do not have the GD library installed, as it is standard with PHP5.
Sep 9 '07 #5
badvoc
44 New Member
Mmhmm.

Is this local or hosted? If it's hosted, you'll need to talk with your host about why they do not have the GD library installed, as it is standard with PHP5.

Hi

It is hosted but on a dedicated server. I have just transfered it to the dedicated as this is what my friend was about to do. Would this mean that I have to install the GD library myself?

Thanks.
Sep 9 '07 #6
pbmods
5,821 Recognized Expert Expert
Heya, badvoc.

If you've got a dedicated server, then it would likely be up to you to reconfigure PHP. You can get in touch with your hosting support team to see if they'll do it for you (for free, at any rate).
Sep 9 '07 #7
badvoc
44 New Member
Heya, badvoc.

If you've got a dedicated server, then it would likely be up to you to reconfigure PHP. You can get in touch with your hosting support team to see if they'll do it for you (for free, at any rate).

Cheers for the reply. I am sorry but I am a total noob at this. I have rang my support team and they are not able to give support on phpadmin other than what they have in their documentation, this only gives brief details, download the latest version of phpadmin, unzip it, rename the folder and ftp it to the server. I have done this and can contect to the database fine. Its just when my site comes to image manipulation thats I get the error message.

I don't seem to be having much luck in finding a no nonesense idiots guide to getting the GD library configured in my phpadmin. The old server, a shared host, is running v2.6.0, the latest is 2.11.0. (If I am stating the obvious, apologies). I am lead to believe that the GD libs are not standard with this release, are they with any release?

Is there a way that I can download them and then ftp them to the server. Or is it more technical that that.

Many thanks for you help.
Sep 9 '07 #8
pbmods
5,821 Recognized Expert Expert
Heya, badvoc.

Alrightey. First thing to do is to create a new page on your server:
Expand|Select|Wrap|Line Numbers
  1. <?php phpinfo(); ?>
  2.  
Run that script and copy what comes up next to 'configure'.

For example (yours will very likely look different than this):
Expand|Select|Wrap|Line Numbers
  1. './configure' '--cache-file=config.cache' '--enable-shared' '--disable-static' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-libxml-dir=/usr/local' '--with-openssl=/usr/local/ssl' '--with-pcre-regex=/usr/local' '--with-zlib-dir=/usr/local' '--with-db4=/usr/local/berkeleydb' '--with-libxml-dir=/usr/local' '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr/local' '--with-freetype-dir=/usr/local' '--with-gd' '--with-iconv=/usr/local' '--with-mysql=/usr/local/mysql' '--with-curl' '--enable-mbstring'
  2.  
Next, download the latest release of PHP to your server. SSH into your dedicated server and type:
Expand|Select|Wrap|Line Numbers
  1. curl http://www.php.net/get/php-5.2.4.tar.bz2/from/this/mirror -o php-5.2.4.tar.bz2
  2. bunzip2 php-5.2.4.tar.bz2
  3. tar -xf php-5.2.4.tar
  4. cd php-5.2.4
  5.  
Then paste the configure line and add '--with-gd' to the end of it. Press return and watch it go.

If at any point it doesn't finish successfully, post back and we'll help you out.

Next execute 'make', then 'make test'. Follow the prompts.

If not too many of the tests fail, execute the following commands:
Expand|Select|Wrap|Line Numbers
  1. apachectl stop
  2. make install
  3. apachectl start
  4.  
If you have any q's or c's post back, and we'll help you out.
Sep 9 '07 #9
badvoc
44 New Member
Heya, badvoc.

Alrightey. First thing to do is to create a new page on your server:
Expand|Select|Wrap|Line Numbers
  1. <?php phpinfo(); ?>
  2.  
Run that script and copy what comes up next to 'configure'.

For example (yours will very likely look different than this):
Expand|Select|Wrap|Line Numbers
  1. './configure' '--cache-file=config.cache' '--enable-shared' '--disable-static' '--with-apxs2=/usr/local/apache2/bin/apxs' '--with-libxml-dir=/usr/local' '--with-openssl=/usr/local/ssl' '--with-pcre-regex=/usr/local' '--with-zlib-dir=/usr/local' '--with-db4=/usr/local/berkeleydb' '--with-libxml-dir=/usr/local' '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr/local' '--with-freetype-dir=/usr/local' '--with-gd' '--with-iconv=/usr/local' '--with-mysql=/usr/local/mysql' '--with-curl' '--enable-mbstring'
  2.  
Next, download the latest release of PHP to your server. SSH into your dedicated server and type:
Expand|Select|Wrap|Line Numbers
  1. curl http://www.php.net/get/php-5.2.4.tar.bz2/from/this/mirror -o php-5.2.4.tar.bz2
  2. bunzip2 php-5.2.4.tar.bz2
  3. tar -xf php-5.2.4.tar
  4. cd php-5.2.4
  5.  
Then paste the configure line and add '--with-gd' to the end of it. Press return and watch it go.

If at any point it doesn't finish successfully, post back and we'll help you out.

Next execute 'make', then 'make test'. Follow the prompts.

If not too many of the tests fail, execute the following commands:
Expand|Select|Wrap|Line Numbers
  1. apachectl stop
  2. make install
  3. apachectl start
  4.  
If you have any q's or c's post back, and we'll help you out.

Thanks, I am trying this now. I have resest the password and have to wait an hour.

Is there another way to do or does it have to be done via ssh?

Cheers
Sep 9 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

11
5313
by: Mike | last post by:
Looking to find any information on how to properly configure multiple instances of DB2. This is on Win2k db2 ver 7.2. I am basically looking for information on how the multiple instance settings should configured to work, how memory is shared or not, etc. I can not seem to find any good links to this information. Thanks, Mike
10
4376
by: Ed Stevens | last post by:
A tale of woe, and a question . . . Last week my boss said to me "we've installed DB2 Connect on this Solaris box. Make it work." Now, I've barely seen DB2 Connect on Windows, having fumbled thru one install and config, with a lot of handholding from IBM Support. I'm comfortable in unix but have never dealt with DB2 Connect there. (my main job is as an Oracle DBA, and most of my db's are on Solaris or AIX) I've found the install...
1
1743
by: Ron Weldy | last post by:
So far, every book I have looks at on ASP.NET jumps right into creating a project. There is no discussion about setting up the environment, using a local IIS install (I think it can all be ran on XP now, right?) vs. having a development server, etc. I will want to eventually maintain several websites using ASP.NET and SQL Server and I have my own development box with W2003 server and IIS6 running. Anybody got some good reference material...
1
3866
by: Jack Orenstein | last post by:
I'm trying to configure PHP 5.2.0 with support for Postgres 8.1.3. Postgres was installed with FC5 without source. PHP's configure needs source. When I run configure: configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path I tried downloading Postgres source and modifying PHPs configure to point to it, and that worked. But then compilation failed, e.g.
1
2227
by: Scubadude | last post by:
I am looking for some assistance in 'fine-tuning' my preferences as I set-up my system to learn PHP. I am running Komodo professional, version 3.5.3, build 262321, platform win32-x86. Under Preferences/Language/PHP in debugger configuration, I am getting the following error message: WARNING! PHP is not configured for debugging. You can use the configuration wizard to configure PHP for debugging.
1
1846
by: RoyScripts | last post by:
Hi All.. I really need help configuring PHP with GD support. I am running Fedora 6, Apache and PHP 5.1.6, i have downloaded the gd-2.0.35 file and unpacked it under the directory /usr/lib/php/gd-2.0.35. I followed the instructions to install it which is as follows. Firstly ./configure --with-gd then make and lastly make install.. Everything installed with no errors. But now when i look at the phpinfo i still get the --without-gd. I really am...
5
13912
pbmods
by: pbmods | last post by:
Configuring PHP 5.2.3 with GD support for Mac OS X PHP 5.2.3 does not seem to want to configure with GD support on Mac OS X for some reason. When configuring, you may notice this error: configure: error: GD build test failed. Please check the config.log for details. Checking config.log yields the following: configure:42434: gcc -o conftest -g -O2 -no-cpp-precomp -L/usr/local/lib -L/usr/local/lib conftest.c -L -lfreetype -lpng...
1
2618
by: rada.lambretha | last post by:
Configuring Linux as a Firewall * Making installation choices * Introducing iptables * Using iptables commands * Simplifying things with firewall GUIs * Adding proxy functionality As Linux gains increasing acceptance in corporate datacenters and
0
8787
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9473
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9259
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8208
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6750
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.