ess14 Posted September 28, 2006 Share Posted September 28, 2006 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]<?phpclass 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> </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> </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 https://forums.phpfreaks.com/topic/22327-using-class/ Share on other sites More sharing options...
Barand Posted September 28, 2006 Share Posted September 28, 2006 try[code]<?phpinclude '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> </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> </td> </tr></table>[/code] Link to comment https://forums.phpfreaks.com/topic/22327-using-class/#findComment-100094 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.