Jump to content

using class


ess14

Recommended Posts

i really suck... can someone tell me how i would implement this class? what would my form look like and how do i make it all work? thanks in advance. i could learn alot from this.

[code]
<?php
class picture
{
      var $save_dir;                    //where file will be saved
      var $filename="spacer.gif";        //default file name initially
      var $error_message="";            //string to be output if neccesary
      var $width;                        //height of final image
      var $height;                      //width of final image

      function picture($save_directory, $file_array, $max_width, $max_height)
      {
              $this->save_dir = $save_directory;             
              $this->width =    $max_width;
              $this->height =  $max_height;

              //--change filename to time - make it unique
              $temp_filename = $file_array['name'];
              $ext = explode('.',$temp_filename);
              $ext = $ext[count($ext)-1];
              $temp_filename = time().".".$ext;

              //--check that it's a jpeg or gif
              if (preg_match('/^(gif|jpe?g)$/',$ext)) {
                      // resize in proportion
                      list($width_orig, $height_orig) = getimagesize($file_array['tmp_name']);
                      if ($this->width && ($width_orig < $height_orig)) {
                              $this->width = ($this->height / $height_orig) * $width_orig;
                      } else {
                              $this->height = ($this->width / $width_orig) * $height_orig;
                      }

                      $image_p = imagecreatetruecolor($this->width, $this->height);                     

                      //handle gifs and jpegs separately
                      if($ext=='gif'){
                          $image = imagecreatefromgif($file_array['tmp_name']);                         
                          imagecopyresampled($image_p, $image, 0, 0, 0, 0, $this->width, $this->height, $width_orig, $height_orig);
                          imagegif($image_p, $this->save_dir.$temp_filename, 80);
                      }
                      else
                      {
                          $image = imagecreatefromjpeg($file_array['tmp_name']);                         
                          imagecopyresampled($image_p, $image, 0, 0, 0, 0, $this->width, $this->height, $width_orig, $height_orig);                         
                          imagejpeg($image_p, $this->save_dir.$temp_filename, 80);
                      }

                      imagedestroy($image_p);
                      imagedestroy($image);

                      $this->filename=$temp_filename;

              }else{
                      $this->error_message.="<br> file is not a jpeg or gif picture <br>";
              }
      }
}
?>
[/code]


and this is my form  :(

[code]
<?php
$save_directory = "users/";
$max_width = 40;
$max_height = 40;
$fileIt = $myclass->picture($save_directory, $max_width, $max_height);
?>
</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><form enctype="multipart/form-data" action="<? $fileIt; ?>" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
 
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form></td>
    <td>&nbsp;</td>
  </tr>
</table>
[/code]

im getting the error that its missing 4 arguments from the picture();
please tell me how stupid i am and what i can do to make this work.
thanks.
Link to comment
Share on other sites

try
[code]
<?php
include 'picture.class.php';

if (isset($_POST['submit'])) {
    $save_directory = "users/";
    $max_width = 40;
    $max_height = 40;
   
$fileIt = new picture($save_directory, $_FILES['userfile'], $max_width, $max_height);
}
?>
</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><form enctype="multipart/form-data" action="" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
 
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form></td>
    <td>&nbsp;</td>
  </tr>
</table>
[/code]
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.