Jump to content

Archived

This topic is now archived and is closed to further replies.

DarkHavn

Couple of simple errors i can't fix

Recommended Posts

Hey, i posted before about a form upload, have sat down and keyed up some ideas, and read through a few tutorials.

Got everything that i'm trying to do in a nutshell, Take a look at the following code

[code]
if($_POST['next']) {


foreach ($_FILES["image"]["error"] as $key => $error) {
$maxfilesize = 734349;
$mimetype = array('image/pjpeg','image/jpeg','image/jpg');
    if($_FILES['image']['size'][$key] >= $maxfilesize){
$errormsg = 'Remember you can not upload a file larger than 700kb, and only .jpg images are allowed!';
break;


// move_uploaded_file($tmp_name, "data/$name");
} else {
$bname = $_SESSION['clients'];
// $tmp_name = $_FILES["image"]["tmp_name"][$key];
      //  $name = $_FILES["image"]["name"][$key];
//$filesize = $_FILES['image']['size'][$key];

    $size = 150; // the thumbnail height
      $filedir = "../../Clients/$bname/images/"; // the directory for the original image
  chmod($filedir, 777);
      $thumbdir = "../../Clients/$bname/images/";  // the directory for the thumbnail image
      $prefix = 'small_'; // the prefix to be added to the original name
      $maxfile = '2000000';
      $mode = '0666';
      $userfile_name = $_FILES['image']['name'][$key];
      echo "$userfile_name";
  $userfile_tmp = $_FILES['image']['tmp_name'][$key];
      $userfile_size = $_FILES['image']['size'][$key];
      $userfile_type = $_FILES['image']['type'][$key];
      if (isset($_FILES['image']['name'][$key])) 
      {
          $prod_img = $filedir.$userfile_name;
          $prod_img_thumb = $thumbdir.$prefix.$userfile_name;
          move_uploaded_file($userfile_tmp, $prod_img);
          //chmod ($prod_img, octdec($mode));
          $sizes = getimagesize($prod_img);
          $aspect_ratio = $sizes[1]/$sizes[0]; 
          if ($sizes[1] <= $size)
          {
              $new_width = $sizes[0];
              $new_height = $sizes[1];
          }else{
              $new_height = $size;
              $new_width = abs($new_height/$aspect_ratio);
          }
          $destimg=ImageCreateTrueColor($new_width,$new_height)
              or die('Problem In Creating image');
          $srcimg=ImageCreateFromJPEG($prod_img)
              or die('Problem In opening Source Image');
          if(function_exists('imagecopyresampled'))
          {
              imagecopyresampled($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg))
              or die('Problem In resizing');
          }else{
              Imagecopyresized($destimg,$srcimg,0,0,0,0,$new_width,$new_height,ImageSX($srcimg),ImageSY($srcimg))
              or die('Problem In resizing');
          }
          ImageJPEG($destimg,$prod_img_thumb,90)
              or die('Problem In saving');
          imagedestroy($destimg);
      }
/*switch($_FILES['image']['type'][$key]){
case 'image/jpeg':
case 'image/pjpeg':
case 'image/jpg':
$bname = $_SESSION['clients'];

//Alright type to cut these images up.
$realwidth = 150;
$realheight = 150;
imagecreatetruecolor($realwidth, $realheight);


  }
}

}
[/code]

Now the following errors i get are

[quote]
Warning: getimagesize(../../Clients/random/images/) [function.getimagesize]: failed to open stream: Permission denied in C:\xampp\xampp\htdocs\localfind\catalogue\update\images.php on line 42

Warning: Division by zero in C:\xampp\xampp\htdocs\localfind\catalogue\update\images.php on line 43

Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in C:\xampp\xampp\htdocs\localfind\catalogue\update\images.php on line 52
Problem In Creating image
[/quote]

I don't see whats going on can someone help me Please!!!

Share this post


Link to post
Share on other sites
Ok scratch that last comment, i've figured out what the problem is

For some odd reason it's not picking up the name of $_FILES['image']['name'][$key];

i dunno why though, in theory it's looping through all of the <input type='file'> feilds and getting the values, but it's not picking up this one for some reason.

:S any ideas?

Share this post


Link to post
Share on other sites
Ok scratch that last comment,

Figured whats going on, since it is looping through, and i havent set up anything to check if one of the upload forms are empty or not, as they don't have to upload all images, just as many as they want, (8 images all up if they want).

Now

[code]
$prod_img = "$filedir" . "$userfile_name";
  echo "$prod_img<br/>";
[/code]

the output of the echo is

[quote]
../../Clients/random/images/Nexer_by_Mxser.jpg
../../Clients/random/images/
[/quote]

How would i go about fixing this one up? as i think i'm getting the errors as its trying to access the last one '../../clients/random/images' instead of the one above it.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.