Jump to content

Couple of simple errors i can't fix


DarkHavn

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!!!
Link to comment
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?
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.