add a percentage loader

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cgrant
Forum Newbie
Posts: 1
Joined: Wed Feb 17, 2010 9:35 pm

add a percentage loader

Post by cgrant »

below is my upload resize code, can someone help me implement a percentage loader to it. I am not sure how to do it thanks

Code: Select all

<form action="<?php echo $_server['php-self'];  ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
        <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
        <button name="submitimg" type="submitimg" class="submitButton">Upload/Resize Image</button>
</form>
<?php
        if(isset($_POST['submitimg'])){
          if (isset ($_FILES['new_image'])){
              $imagename = $_FILES['new_image']['name'];
              $source = $_FILES['new_image']['tmp_name'];
              $target = "photos/".$imagename;
              move_uploaded_file($source, $target);
 
              $imagepath = $imagename;
              $save = "photos/" . $imagepath; //This is the new file you saving
              $file = "photos/" . $imagepath; //This is the original file
 
              list($width, $height) = getimagesize($file) ; 
 
              $modheight = 350; 
 
              $diff = $height / $modheight;
 
              $modwidth = $width / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
 
              imagejpeg($tn, $save, 100) ; 
 
              $save = "photos/thumbs/" . $imagepath; //This is the new file you saving
              $file = "photos/" . $imagepath; //This is the original file
 
              list($width, $height) = getimagesize($file) ; 
 
              $modheight = 100; 
 
              $diff = $height / $modheight;
 
              $modwidth = $width / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0,$modwidth, $modheight, $width, $height) ; 
 
              imagejpeg($tn, $save, 100) ; 
            echo "Large image: <img src='photos/".$imagepath."'><br>"; 
            echo "Thumbnail: <img src='photos/thumbs/".$imagepath."'>"; 
 
          }
        }
?>
Last edited by Benjamin on Mon Feb 22, 2010 9:04 pm, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: add a percentage loader

Post by Benjamin »

Post Reply