Upload path syntax in script - help!

Now i’m in trouble.
Second attempt in remote debugging and fail again.
Everything seems to be o.k…

error in the file_exists function may be?
try to change this line

if(!file_exists($_FILES[$this->field_name][tmp_name])){

to this

if(!$_FILES[$this->field_name][tmp_name]){

and run again, but first remove previous code - with print_r and die one

returned:
This type of image cannot be manipulated.

which isn’t the case - it was a small jpg that the script has handled just fine in the past.

  • michael

Before you begin losing hair over this, please keep in mind that this script worked under PHP 4.x, as is (with the only change being the upload path to user_images).

And that’s why I suspected that the easiest way to get it working on the current server would be to get an appropriate version of PHP installed and setup properly.

  • michael

that’s fine.
we’ve got much closer.

now it’s time to check if GD enabled. looks like no.
you can run this code
<?php phpinfo(); ?>
in the separate file and study output
there GD must be mentioned.
if not - you have to uncomment it in the proper php.ini

Before you begin losing hair

hah, forget it :slight_smile:
it’s my usual job. any programmer spend most of his work time for the debugging. nothing to lose hair for.
just step-by-step diagnostics.

Version doesn’t matter too much for this. And proper setup is the thing you going to check right now :slight_smile:

There might be a problem with the GD extension. For debugging, go through the class files code and change all the error suppressors eg.

if($_FILES[$this->field_name][type]=='image/jpeg' OR $_FILES[$this->field_name][type]=='image/pjpeg'){
if(function_exists('imagecreatefromjpeg')){
//$im = @imagecreatefromjpeg($_FILES[$this->field_name][tmp_name]);
$im = imagecreatefromjpeg($_FILES[$this->field_name][tmp_name]);
}else{
echo $this->error(6);
exit;

This way you can get the hopefully more helpful PHP error messages instead of the class file’s custom error message.

GD2.DLL is located in C:\PHP\ext\
and it is enabled in php.ini

  • michael

ok, ok
but does it show in the phpinfo()?

www.sittercafe.com/phpinfo.php

That didn’t change the way the browser displayed the script error text.


   ##--------------------------------------------
   ##MAKE IMAGE FUNCTION
   ##Makes image
   ##--------------------------------------------
   function make_image($location, $image, $size, $width, $height){
      if($_FILES[$this->field_name][type]=='image/gif'){
         if(function_exists('imagecreatefromgif')){
            [COLOR="Red"]//$im = @imagecreatefromgif($_FILES[$this->field_name][tmp_name]);[/COLOR]
	      [COLOR="SeaGreen"]$im = imagecreatefromgif($_FILES[$this->field_name][tmp_name]);[/COLOR]         }else{
            echo $this->error(6);
            exit;
         }
      }
      if($_FILES[$this->field_name][type]=='image/jpeg' OR 

$_FILES[$this->field_name][type]=='image/pjpeg'){
         if(function_exists('imagecreatefromjpeg')){
            [COLOR="red"]//$im = @imagecreatefromjpeg($_FILES[$this->field_name][tmp_name]);[/COLOR]
              [COLOR="seagreen"]$im = imagecreatefromjpeg($_FILES[$this->field_name][tmp_name]);[/COLOR]
         }else{
            echo $this->error(6);
            exit;
         }
      }
      if($_FILES[$this->field_name][type]=='image/x-png'){
         if(function_exists('imagecreatefrompng')){
            [COLOR="Red"]//$im = @imagecreatefrompng($_FILES[$this->field_name][tmp_name]);[/COLOR]
              [COLOR="seagreen"]$im = imagecreatefrompng($_FILES[$this->field_name][tmp_name]);[/COLOR]
         }else{
            echo $this->error(6);
            exit;
         }
      }

      if(!$im){
            echo $this->error(7);
            exit;
      }else{
         $dst_img = imagecreatetruecolor($width,$height);
         imagecopyresized($dst_img, $im, 0, 0, 0, 0, $width, $height, $size[0], $size[1]);
         imagejpeg($dst_img, $location, 75);
         array_push($this->output, $location);
      }


   }

www.sittercafe.com/phpinfo.php

So, it isn’t enabled.

Well, I think that’s your problem. I don’t see any reference at all to GD it it. There are some differences, I have LAMP PHP 5.2.6, but my phpinfo() shows

Configure Command
  './configure' '--prefix=/usr/local/php5' '--enable-fastcgi'
 '--with-mysql=/usr' '--enable-calendar' '--with-mhash=/usr'
 '--with-kerberos' '--enable-force-cgi-redirect' '--with-config-file-path=/etc/php5/cgi'
 '--with-imap' '--with-imap-ssl' '--enable-trans-sid'
 [B]'--with-gd'[/B] '--with-xml' '--with-xsl' '--with-ttf=/usr'
 '--with-freetype-dir=/usr' '--enable-exif' '--with-xslt'
 '--with-xslt-sablot=/usr' '--with-dom-xslt=/usr' '--with-jpeg-dir=/usr'
 '--with-png-dir=/usr' '--with-zlib-dir=/usr' '--with-pdo-mysql'
 '--enable-ftp' '--with-curl=/usr' '--with-pspell=/usr'
 '--enable-mbstring' '--with-mcrypt' '--with-mysqli'
 '--with-openssl=/usr' '--with-gettext'  

and

gd
GD Support  enabled  
GD Version  bundled (2.0.34 compatible)  
FreeType Support  enabled  
FreeType Linkage  with freetype  
FreeType Version  2.2.1  
GIF Read Support  enabled  
GIF Create Support  enabled  
JPG Support  enabled  
PNG Support  enabled  
WBMP Support  enabled  
XBM Support  enabled  

:d’oh: my bad

That’s because the function doesn’t exist. Still, you should probably leave it that way until you get everything configured correctly and are sure everything is working again.

i’m at a loss…

gd2.dll is enabled in php.ini
and the dll is located in the ext dir.

  • michael

Is it enabled in the php.ini file identified as the “Loaded Configuration File” in phpinfo() ?

I don’t know how your Windows server is set up, but my XAMPP localhost server has 2 php.ini files. One in …/apache/bin/ and another in …/php/

My guess is you also have more than one php.ini file and you need to change the other(s) as well.

extension_dir must be set too.
also, be sure you edit C:\PHP\php.ini file

gd2.dll is enabled in php.ini
and the dll is located in the ext dir
and c:\php\ext\ is listed in php.ini as the extensions directory.

Today I am going to remove all PHP files from the server, inlcuding php.ini, restart the server, remove all dll’s and then install PHP from scratch.

I’ll update the thread here with the results and status.

Thanks for all of your input.

  • michael

PHP looks for php.ini in a set order, in several places (and I do have php.ini in each of those locations). When I make a change in php.ini, I copy it to all of those locations and restart my server.

PHP looks for php.ini in a set order, in several places (and I do have php.ini in each of those locations). When I make a change in php.ini, I copy it to all of those locations and restart my server.

This php.ini craze may cause this trouble
php.ini listed in phpinfo() is enough

At first I’d check if any my php.ini changes take effect. Any options. And only then go to particular library
Did you restart server after changes made?

Yes, of course - I restart the server after each change to php.ini. (Is there a way to JUST restart php w/o having to restart the server? - I hate dumping people off of my website each time I reboot).

I have removed earlier installation of PHP and used the Zend package to install PHP 5.2. GD library is installed and I am currently testing the overall installation on the server.

stay tuned…

  • michael