Link to home
Create AccountLog in
Avatar of doctorbill
doctorbillFlag for United Kingdom of Great Britain and Northern Ireland

asked on

php file upload

In the attached file I have the following code:
---------------------------
$formfile = "";
            
      if($_FILES['art_Thumb'] && $_FILES['art_Thumb']['size'] > 0){
            $uploaddir = "images/artists/thumb/";  //folder in which to put the file
            $ori_name = $_FILES[art_Thumb][name];
            $tmp_name = $_FILES[art_Thumb][tmp_name];
            $src = imagecreatefromjpeg($tmp_name);
            list($width,$height) = getimagesize($tmp_name);
            //landscape
            if ($width > $height) {
                  $pwidth = 450;
                  $newwidth = $pwidth;
                  $newheight = ($height/$width)*$pwidth;
            }
            //
            //portrait
            if ($height > $width) {
                  $pwidth = $width;
                  $newheight = 450;
                  $newwidth = ($width/$height)*$newheight;
            }
            //
            $tmp = imagecreatetruecolor($newwidth,$newheight);
            imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
            $newfile = $uploaddir.$ori_name;
            imagejpeg($tmp,$newfile,100);
            chmod($newfile,0777);
      }
-------------------------

This is working firn for most xxx.jpg images but some images are just not being uploaded. The ones not being uploaded are still xxx.jpg and I cannot see what the problem is. All images are always > 1000 pixels wide

Help Help  please
frm-artgallery.php
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of doctorbill

ASKER

The file is uploaded with your script - where is the destination folder please
sorry - found it
Ray:
I found the issue with my script:
this part caused a problem is the image was a perfect square:
 if ($height > $width)

Changing it to  if ($height >= $width) solved the problem


On another note - re. the redirect url issue you very kindly sorted out for me yesterday::
                  
      $redirect = $redirect
= 'frm_artgallery.php?'
. 'artist_added='
. urlencode($_POST['art_Nme'])
. '&'. 'image_added='
. urlencode($_POST['art_title'])
;

This works if the image name does not have a space in it: image2.jpg
If it does have a space it does not work: image 2.jpg

Can you suggest a fix please - I realise that you have already answered this
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Solution