upload image and file path name

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
Alidad
Forum Commoner
Posts: 29
Joined: Thu Mar 29, 2007 12:42 pm

upload image and file path name

Post by Alidad »

Hi, i need help, i'm trying to find how to write code to allow me to create upload images and save in the folder and input images file path name in database.

I have tried to find from google but so far nothing, does anyone can help me if you know the site where i can learn more about upload images and file path name in mysql!

AM
Alidad
Forum Commoner
Posts: 29
Joined: Thu Mar 29, 2007 12:42 pm

Re: upload image and file path name

Post by Alidad »

i just send you email but then i got auto response said that is consider of spam.

here is code...

i just need to know how can i writ code to send image path to the database and store images in folder, and to view images using database.

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="submit" type="submit" class="submitButton">Upload/Resize Image</button>
</form>
<?php
        if(isset($_POST['submit'])){
          if (isset ($_FILES['new_image'])){
              $imagename = $_FILES['new_image']['name'];
              $source = $_FILES['new_image']['tmp_name'];
              $target = "images/".$imagename;
              move_uploaded_file($source, $target);
              
              $imagepath = $imagename;
              $save = "images/" . $imagepath; //This is the new file you saving
              $file = "images/" . $imagepath; //This is the original file
 
              list($width, $height) = getimagesize($file) ; 
                                                         
              $modwidth = 150; 
                                                         
              $diff = $width / $modwidth;
                                                        
              $modheight = $height / $diff; 
              $tn = imagecreatetruecolor($modwidth, $modheight) ; 
              $image = imagecreatefromjpeg($file) ; 
              imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; 
                                                        
              imagejpeg($tn, $save, 100) ; 
 
              $save = "images/sml_" . $imagepath; //This is the new file you saving
              $file = "images/" . $imagepath; //This is the original file
 
              list($width, $height) = getimagesize($file) ; 
                                                         
              $modwidth = 80; 
                                                         
              $diff = $width / $modwidth;
                                                        
              $modheight = $height / $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='images/".$imagepath."'><br>"; 
            echo "Thumbnail: <img src='images/sml_".$imagepath."'>"; 
        
          }
        }
?>
stevejack
Forum Newbie
Posts: 2
Joined: Tue Sep 15, 2009 4:38 am

Re: upload image and file path name

Post by stevejack »

You can name all your image pages using the file name of its full-size image. Simply check the Use image file name box. The resulting page file name will have the name of the image file plus the extension you enter into the Extension box. For example: photo1.jpg.html. If you do not want to add the image file extension to the page file name, then clear the Add image extension box and result will be the following: photo1.html.
Post Reply