SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help me with this image thumbnails php

    I am just stuck with this............Please Please Help


    I got following fields in the forms for now
    my form is as follow:

    { register.html }
    <form action="register.php" method="post" enctype="multipart/form-data">
    Username: <input type="text" name="username"><br>
    Password: <input type="password" name="password"><br>
    Photo 1: <input type="file" name="photo"><br>
    Photo 2: <input type="file" name="photo2"><br>
    Photo 3: <input type="file" name="photo3"><br>
    Photo 4: <input type="file" name="photo4"><br>
    <input type="submit" name="register" id="button" value="Register">
    </form>
    Actually, Now I can upload four pictures into the images/user folder but with no thumbnails
    Original Image : Remain same --> Upload
    Thumbnail Image: Resize to 80 X 80 px --> Upload

    Currently, it will upload four images with different unique random number for 4 images without dothing anything and put it into the database (image names only).

    I want to create the thumbnail with the same name as the images name it will be in the database but with starting like:

    Main image: myfile.jpg
    Thumbnail: thmyfile.jpg

    My register member with photo uploads. Page {register.php}

    <?php
    ob_start();
    // allows you to use cookies
    include("database.php");
    //gets the config page



    if ($_POST[register]) {
    $username = $_POST[username];
    $password = $_POST[pass];

    $ran1 = rand () ;

    $ran1 = $ran1."_";

    $ran2 = rand () ;
    $ran2 = $ran2."_";

    $ran3 = rand () ;
    $ran3 = $ran3."_";


    $ran4 = rand () ;
    $ran4 = $ran4."_";

    $folder = "images/users/";


    $target = $folder .$ran1. basename( $_FILES['photo']['name']);
    $target2 = $folder .$ran2. basename( $_FILES['photo2']['name']);
    $target3 = $folder .$ran3. basename( $_FILES['photo3']['name']);
    $target4 = $folder .$ran4. basename( $_FILES['photo4']['name']);

    //thumb create
    $target5 = $folder_th .$ran1. basename( $_FILES['photo']['name']);
    $target6 = $folder_th .$ran2. basename( $_FILES['photo2']['name']);
    $target7 = $folder_th .$ran3. basename( $_FILES['photo3']['name']);
    $target8 = $folder_th .$ran4. basename( $_FILES['photo4']['name']);

    //make variable for easier use
    $pic = $ran1. basename( $_FILES['photo']['name']);
    $pic2 = $ran2. basename( $_FILES['photo2']['name']);
    $pic3 = $ran3. basename( $_FILES['photo3']['name']);
    $pic4 = $ran4. basename( $_FILES['photo4']['name']);

    if($username==NULL|$password==NULL) {
    echo "A field was left blank.";
    }else{
    if($password != $cpassword) {
    echo "Passwords do not match";
    }else{

    $password = md5($password);
    $checkname = mysql_query("SELECT username FROM users WHERE username='$username'");
    $checkname= mysql_num_rows($checkname);

    $checkemail = mysql_num_rows($checkemail);
    if ($checkname>0) {
    echo "The usernameis already in use";
    }else{
    $username = htmlspecialchars($username);
    $password = htmlspecialchars($password);

    $pic = htmlspecialchars($pic);
    $pic2 = htmlspecialchars($pic2);
    $pic3 = htmlspecialchars($pic3);
    $pic4 = htmlspecialchars($pic4);


    $query ="INSERT INTO users (username, password pic, pic2 ,pic3, pic4)
    VALUES('$username','$password','$pic','$pic2','$pic3','$pic4' )";

    $res=mysql_query($query) or die ("Error: ". mysql_error(). " with query ". $query);

    echo "You have successfully registered!";
    echo "<br />";

    if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
    {
    echo "Image 1 has been added";
    echo "<br />";
    }

    else {

    echo "Sorry, there was a problem uploading Image 1.";
    }

    if(move_uploaded_file($_FILES['photo2']['tmp_name'], $target2))
    {
    echo "Image 2 has been added";
    echo "<br />";
    }

    else {

    echo "You didn't upload Image 2.";
    echo "<br />";
    }

    if(move_uploaded_file($_FILES['photo3']['tmp_name'], $target3))
    {
    echo "Image 3 has been added";
    echo "<br />";
    }

    else {
    echo "You didn't upload Image 3.";
    echo "<br />";
    }

    if(move_uploaded_file($_FILES['photo4']['tmp_name'], $target4))
    {

    echo "Image 4 has been added";
    echo "<br />";
    }


    else {
    echo "You didn't upload Image 4.";
    echo "<br />";
    }

    }
    }
    }
    }
    else
    {
    include 'register.html'; }
    ?>


    Please help me how can I do with this script,By the way if anybody knows any free script to upload 4 photos with thumbnail
    and insert into the dabase, name only.


    Thanks a lot for your help

  2. #2
    SitePoint Wizard Darren884's Avatar
    Join Date
    Aug 2003
    Location
    Southern California, United States
    Posts
    1,616
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all you need to define $folder_th or perhaps concate the filename like:
    $target5 = $folder . 'th' . $ran1. basename( $_FILES['photo']['name']);.

    After you have fixed that apply the thumbnailing functions when you move it.

    If you wanted to store the file in the database you would have to encode it and put it in a blob field.
    Have a good day.

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi, can someone please direct to the correct way.as mention above.

    1. How can I generate the thumbnails(4thumbnails) from the above script as I have uploaded the four pictures

    2. How to insert the picture name only if the user upload the picture otherwise don't put the name into the database [as from the above script]

    Thanks a lot


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •