Jump to content

Upload > watermark > thumbnail


Dat

Recommended Posts

I have created a form that will add an entry.

 

I want to add a upload form in that entry what will upload an image (while or before insert filename[example: dog.jpg] in database), add a watermark and put that in a folder (say... /anime/images) and then create a thumbnail of that image into another folder (say.. anime/images/tn_images).

 

I don't know anything about GD

 

So.. what I'm asking is a referral to a site tutorial or reply on how to do this? Thank you.

Link to comment
Share on other sites

I currently have a simple image uploader

 

<html>

<head>
<title>Upload File</title>
</head>

<form action="upload.php" method="post" enctype="multipart/form-data">
Browse a File to Upload:<br>
<input type="file" name="filetoupload"><br>
<input type="hidden" name="Maximum File Size" value="<?echo $size_bytes; ?>">
<br>
<input type="Submit" value="Upload File">
</form>
<?php
$upload_dir = "images/";
// files less than 1MB
$size_bytes = 1048576; //bytes  will be uploaded
$limit_file_type = "yes"; //(yes/no)
// specify file types.
$allowed_file_type = array('image/gif',
                          'image/pjpeg',
                          'image/jpeg',
                          'image/png',
                          'image/jpg');

         //check if the directory exist or not.
         if (!is_dir("$upload_dir")) {
     die ("The directory <b>($upload_dir)</b> doesn't exist");
         }
         //check if the directory is writable.
         if (!is_writeable("$upload_dir")){
            die ("The directory <b>($upload_dir)</b> is NOT writable, Contact Arrangements");
         }
if (is_uploaded_file($_FILES['filetoupload']['tmp_name']))
{
        //Get the Size of the File
        $size = $_FILES['filetoupload']['size'];
        //Make sure that $size is less than $size_byte
        if ($size > $size_bytes)
        {
            echo "File Too Large. File must be <b>$size_bytes</b> bytes.";
            exit();
        }
             //check file type
        if (($limit_file_type == "yes") && (!in_array($_FILES['filetoupload']['type'],$allowed_file_type)))
        {
            echo"wrong file type";
            exit();
        }

        // $filename will hold the value of the file name submetted from the form.
        $filename =  $_FILES['filetoupload']['name'];
        // Check if file is Already EXISTS.
        if(file_exists($upload_dir.$filename)){
            echo "Oops! The file named <b>$filename </b>already exists";
            exit();
        }

        //Move the File to the Directory of your choice
        //move_uploaded_file('filename','destination') Moves afile to a new location.
        if (move_uploaded_file($_FILES['filetoupload']['tmp_name'],$upload_dir.$filename)) {

           //tell the user that the file has been uploaded and make him alink too;).
           echo "File (<a href=$upload_dir$filename</a>) uploaded!";
           exit();

        }
        else
        {
            //Print error
            echo "There was a problem moving your file";
            exit();
        }
}//end of is_uploaded_file IF
?>

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.