Jump to content

jwmstudios

Members
  • Posts

    21
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jwmstudios's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for the tip, i see what you are saying, i am working on a new uploader.
  2. i understand now i should of separated the classes and let them interact.
  3. "Why would Image extend Uploader? They don't seem at all related." its simple, uploader uploads the file and image manipulates the file uploaded, you can have a subclass called videos extending from uploader as well as pdf and other mime types etc. its unlimited ideas that can be spawned.
  4. i know, alot of bugs are there, but its a class that can be built on.
  5. I also added a image re-sizer for those that are interested in resizing an image and sending it to a new path, it was a challenge creating this and i know its buggy thats why i seek a community such as this one to help me to find them and we can all share good code to make our work flow faster. Antway here is the class, call it uploader_bk.php <?php /* This is a simple file uploader class created by me: Hugo Johnson website: www.jwmstudios.com email: hugoj@hotmail.com Its my first real shot at creating a php class, i am still a todler to this. The Class called uploader is responsible for creating a file field and a single form, or many file fields (without a form) It then uploads the chosen file to a specified path, once you click on the browse button and submitt the form. The Sub-Class called Image is used to both upload the image to a chosen path as well as create a thumbnailed copy this thumbnail can be resized based of the new height parameter that is passed in by the user. Needs more work and validation but enjoy. */ Class Uploader { // Declaring my variables needed for this class, it makes sense. public $input_field_name = "userfile"; // default input field name public $file_size =300000; // default file size public $path_directory = ""; // location to send the file public $action_path_and_file = "uploader.php"; // default form action function form() { // This form is optional used if no form is provided, only good for one file echo <<<END <form enctype="multipart/form-data" method="post" action="$this->action_path_and_file "> <input name="$this->input_field_name" type="file" /><br /><input type="hidden" name="max_size" value="$this->file_size" /> <input type="submit" value="Upload" /> </form> END; } function file_field($field_name) { // optional for adding more than one file echo "<br /><input name=\"$field_name\" type=\"file\" /><br />"; } function upload($input_field_name) { // this will upload a file that coresponds to a field name of type file $filename = $_FILES[$input_field_name]['name']; // coming from the form $filesize = $_FILES[$input_field_name]['size']; // " " $temp = $_FILES[$input_field_name]['tmp_name']; // " " // move Uploaded File function places the file from its temp directory and puts it into the desired directory, $path = $this->path_directory.$filename; // you can type a path directory structure between the quotes eg. ../ or /filestorage etc. $uploadfile = move_uploaded_file($temp, $path); // moving file from temp location to new chosen path // echo $uploadfile === TRUE ? '<br />File uploaded<br />' : '<br />Awaiting File Upload<br />'; // echo "<br />".$this->path_directory.$filename."<br />"; if($uploadfile === TRUE) { echo '<br />Congrats file uploaded<br />'; // These are optional outputs for testing purpose return TRUE; } else { echo '<br />Awaiting File Upload<br />'; // These are optional outputs for testing purpose return FALSE; } } } Class Image extends Uploader{ // Declaring my varaibles public $newpath; // This will be the new location of the thumbnail image public $new_height; // This parameter will specify the size of thumbnail function fetch_filename($input_field_name){ // simple utilty for testing purpose return $filename = $_FILES[$input_field_name]['name']; } function resizeimage($x) { // begin image resizer x is the fieldname $filename = $_FILES[$x]['name']; // generating the file name from the field name // echo $this->path_directory.$filename; // echo "<br />new path:".$this->newpath.$filename; // Tsting to see if is correct extension. $ext = strrchr($filename, '.'); switch ($ext) { case ".jpg": $im = imagecreatefromjpeg($this->path_directory.$filename); break; case ".gif": $im = imagecreatefromgif($this->path_directory.$filename); break; case ".png": $im = imagecreatefrompng($this->path_directory.$filename); break; default: $im = imagecreatefromstring(file_get_contents($this->path_directory.$filename)); } $get_image = $im; // assigning get image to im variable // if($get_image === True) { echo "get image is true!";} if ($get_image === false) { die ('Unable to open image'); // scipt ends if stuff goes wrong } // Get original width and height $width = imagesx($get_image); $height = imagesy($get_image); // Set a new width, and calculate new height $new_width = $width * ($this->new_height/$height); // Resample the image $image_resized = imagecreatetruecolor($new_width, $this->new_height); imagecopyresampled($image_resized, $get_image,0 , 0,0 ,0 , $new_width, $this->new_height, $width, $height); //imagejpeg($image_resized_big, $path_thumb); imagejpeg($image_resized, $this->newpath.$filename); } // end of image resizer } ?> here is the test form: <?php // This is the test upload form include_once("uploader_bk.php"); // importing the Uploader class //============================ VARAIBLE DECLARATIONS =============================== $myupload = new Image(); // declaring a new uploader object $myupload->file_size = 400000; // setting a different file size $myupload->path_directory = "myfiles/"; // You can mod the path directory at any time, leave blank if is on the same path as the script $myupload->action_path_and_file = $_SERVER['PHP_SELF']; // use $_SERVER['PHP_SELF'] if its the same script that is doing the processing $fieldname = array("joe", "Mary"); // This can apply to one file you may need to prefix variable names to add more fields; this could also be an include $max_fields = count($fieldname); // getting the maximum number of fields that you need could be an include $myupload->newpath = $myupload->path_directory."thumbs/"; // The path for the thumbs directory $myupload->new_height = 100; // the new height parameter for the thumbnail image //================================================================================== ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Handling File Uploads</title> </head> <body> <form enctype="multipart/form-data" method="post" action="<?php echo $myupload->action_path_and_file; // path to the process script ?>"> <?php // Simple for loop that will repeat the steps based off the max_fields varaible. for ($i=0 ; $i < $max_fields; $i++) { $myupload->file_field($fieldname[$i]); // input field. $upload = $myupload->upload($fieldname[$i]); // file uploader if($upload === TRUE) { // Testing to see if upload variable returns a true value $myupload->resizeimage($fieldname[$i]); // image resizer } } ?> <input type="submit" value="Send File" /> </form> </body> </html> my next mission is to fuse it with a MySQL Class so that i can reference the files in a database and also a remover function that will remove my files from both the server and the database, some assistance / guidance will be greatly appreciated.
  6. i made a little uploader class, its not refined but it works, here is the class <?php /* This is a simple file uploader class created by me: Hugo Johnson website: www.jwmstudios.com email: hugoj@hotmail.com Its my first real shot at creating a php class, i am still a todler to this. */ Class Uploader { // Declaring my variables needed for this class, it makes sense. public $input_field_name = "userfile"; // default input field name public $file_size =300000; // default file size public $path_directory = ""; // location to send the file public $action_path_and_file = "uploader.php"; // default form action function form() { // This form is optional used if no form is provided, only good for one file echo <<<END <form enctype="multipart/form-data" method="post" action="$this->action_path_and_file "> <input name="$this->input_field_name" type="file" /><br /><input type="hidden" name="max_size" value="$this->file_size" /> <input type="submit" value="Upload" /> </form> END; } function file_field($field_name) { // optional for adding more than one file echo "<br /><input name=\"$field_name\" type=\"file\" /><br />"; } function upload($input_field_name) { // this will upload a file that coresponds to a field name of type file $filename = $_FILES[$input_field_name]['name']; // coming from the form $filesize = $_FILES[$input_field_name]['size']; // " " $temp = $_FILES[$input_field_name]['tmp_name']; // " " // move Uploaded File function places the file from its temp directory and puts it into the desired directory, $path = $this->path_directory.$filename; // you can type a path directory structure between the quotes eg. ../ or /filestorage etc. $uploadfile = move_uploaded_file($temp, $path); // moving file from temp location to new chosen path echo $uploadfile === TRUE ? '<br />File uploaded<br />' : '<br />Awaiting File Upload<br />'; } } ?> Save the file as uploader_bk.php Here is the test form: <?php // This is the test upload form include_once("uploader_bk.php"); // importing the Uploader class $myupload = new Uploader(); // declaring a new uploader object $myupload->file_size = 400000; // setting a different file size $myupload->path_directory = "myfiles/"; // You can mod the path directory at any time, leave blank if is on the same path as the script $myupload->action_path_and_file = $_SERVER['PHP_SELF']; // use $_SERVER['PHP_SELF'] if its the same script that is doing the processing $fieldname = array("joe", "Mary"); // This can apply to one file you may need to prefix variable names to add more fields; this could also be an include $max_fields = count($fieldname); // getting the maximum number of fields that you need echo "<br />"; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Handling File Uploads</title> </head> <body> <form enctype="multipart/form-data" method="post" action="<?php echo $myupload->action_path_and_file; ?>"> <?php for ($i=0 ; $i < $max_fields; $i++) { $myupload->file_field($fieldname[$i]); // input field. $myupload->upload($fieldname[$i]); // The uploading process. } ?> <input type="submit" value="Send File" /> </form> </body> </html>
  7. Ok i modified the get page using unset as suggested, it worked! <?php // Start Your Session each time save this file as get.php session_start(); $name = $_SESSION['name']; // this is the original variable data that you want to store echo "my name is ".$name; // output on screen unset($_SESSION['name']); // resetting my session variable using unset function if(!isset($_SESSION['name'])) { $_SESSION['name'] = "Joe"; // reassign session variable to joe } echo "<br /><a href=\"testpost.php\" >go back</a>"; ?>
  8. Ok after a few weeks of frustration i figured out how to get my variables to go back and forth pages without using register_globals = on ok here is some test code: First create a file called testpost.php copy and paste this data: <?php session_start(); echo "<a href=\" get.php \" >Click here </a><br />"; // looking for a returned value named Joe if ($_SESSION['name'] == "Joe") { echo "Well What do you know i am".$_SESSION['name']."<br />"; // output on screen } // Well if i didn't find it, just call it mary. $_SESSION['name'] = "mary"; ?> fine then create another file in the same directory called get.php copy and paste this into it: <?php // Start Your Session each time save this file as get.php session_start(); $name = $_SESSION['name']; // this is the original variable data that you want to store echo "my name is ".$name; // output on screen $_SESSION['name'] = ""; // resetting my session variable if($_SESSION['name'] == "") { $_SESSION['name'] = "Joe"; // reassign session variable to joe } echo "<br /><a href=\"testpost.php\" >go back</a>"; ?> ok give it a test and then modify as you like, you don't have to send your variables across your web browser dudes, enjoy!
  9. is there a way to manually upload files (images folder zipped) to a server and direct php script to the path of the server and let it extract the files and resize and thumbnail them?
  10. what is a framework and how do i learn it? I keep hearing that it is used to rapidly create applications, i heard about cake php, zend and few otherwise. But how do i get started?
  11. The Problem with those applications the code seem complex as they use complex classes with xml and they don't comment on functionality within their code, but i created this thread with the hope that someone out there has been through this roadblock before and have useful code. I will post my findings to this thread when i get through.
  12. Hello everyone I have built a photo gallery application, but i would like to add a feature where i can manually create a folder within a directory and php is able to detect the files for me and also generate thumbs (previews). I can then choose which file i want to include in my database eg album, category etc. I sort of want it to function like coppermine photo gallery admin tools. Is there any code that i can start with?
  13. Now that you mentioned it, i think having multiple forms is better even for the validation process.
×
×
  • 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.