Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-06-2009, 02:50 PM   PM User | #1
FIA2008
New to the CF scene

 
Join Date: Jun 2009
Location: Utrecht, Holland
Posts: 9
Thanks: 1
Thanked 0 Times in 0 Posts
FIA2008 is an unknown quantity at this point
how to generate a thumbnail?

How can I generate a thumbnail with script?
PHP Code:
<?php
/* Start Verwerking */
if($_SERVER['REQUEST_METHOD'] == 'POST'){
    
$ext            $_FILES['type'];
    
$file_name        md5(rand(01000).'-'.time()).$ext.".jpg";
    
$target_path    "../photo/".$_POST['album']."/".$file_name;
    
$ar        = array();
    
$ar[0]    = 'image/jpeg';
    
    
$title            mysql_real_escape_string($_POST['title']);
    
$description    mysql_real_escape_string($_POST['description']);
    
$album            mysql_real_escape_string($_POST['album']);

    if(isset(
$_POST['send'])){
        
$fouten = array();
        if (empty(
$_POST['title'])){
            
$fouten[] = "Geen naam ingevuld!";
        }
        if(empty(
$_POST['description'])){
            
$fouten[] = "Geen beschrijving ingevuld!";
        }
        if(empty(
$_POST['album'])){
            
$fouten[] = "Geen album opgegeven!";
        }
        if(empty(
$_FILES['file']['name'])){
            
$fouten[] = "Geen foto geselecteerd!";
        }
        if(!
in_array($_FILES['file']['type'],$ar)){
            
$fouten[] = "Verkeerd bestandstype!";
        }
        
$counter count($fouten);
        if(
$counter 0){
        echo 
"    <font color='#FF0000'>
                    <ol>
                        <font color='#000000'>De volgende velden zijn niet correct ingevuld:</font>
                        <li>"
.join("</li>
                        <li>"
$fouten)."</li>
                    </ol>
                </font>"
;
        }
    }
    if(
$counter == 0){
        if(
in_array($_FILES['file']['type'],$ar)){            
            
$sql "INSERT INTO photo_photo(id, title, description, album, file)
            VALUES ('','"
.$title."', '".$description."', '".$album."', '".$file_name."')";
            
mysql_query($sql);
            
move_uploaded_file($_FILES['file']['tmp_name'], $target_path);
            echo 
"<br>Foto is succesvol ge&uuml;pload en in het album geplaatst.<br>";
        }
    }
}
/* Einde Verwerking */
$photo    "SELECT * FROM photo_photo";
$photo    mysql_query($photo);
$album    "SELECT * FROM photo_album ORDER BY id";
$album    mysql_query($album);
?>
<form name="photo_add" method="post" action="<?php $_SERVER['PHP_SELF'?>" enctype="multipart/form-data">
<table>
    <tr>
        <td>Naam</td>
        <td><input type="text" name="title" size="45" /></td>
    </tr>
    <tr>
        <td>Beschrijving</td>
        <td><textarea name="description" cols="34"></textarea></td>
    </tr>
    <tr>
        <td>Album</td>
        <td>
            <select name="album">
            <?php
            
while($album_rij mysql_fetch_array($album)){
                
?>
                <option value="<?php echo $album_rij[0?>"><?php echo $album_rij[1?></option>
                <?php
            
}
            
?>
            </select>
        </td>
    </tr>
    <tr>
        <td>Selecteer een foto</td>
        <td><input type="file" name="file" size="45" /></td>
    </tr>
    <tr>
        <td></td>
        <td><input type="submit" value="Foto toevoegen" name="send" /></td>
    </tr>
</table>
</form>
FIA2008
FIA2008 is offline   Reply With Quote
Old 07-31-2009, 09:04 AM   PM User | #2
thales.jacobi
New to the CF scene

 
Join Date: Jul 2009
Posts: 4
Thanks: 0
Thanked 1 Time in 1 Post
thales.jacobi is an unknown quantity at this point
$big_file=$_FILES['file']['tmp_name'];
$new_file='/tmp/thumbnail.jpg';

copy($big_file, $new_file);

$thumb_width=50;
$thumb_height=35;

$thumb = imagecreatetruecolor($thumb_width,$thumb_height);
$source = imagecreatefromjpeg($big_file);
imagecopyresized($thumb,$source,0,0,50,35,$thumb_width,$thumb_height,188,188);

imagejpeg($thumb,$new_file);
thales.jacobi is offline   Reply With Quote
Reply

Bookmarks

Tags
generate, php, script, thumbnail

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:02 AM.


Advertisement
Log in to turn off these ads.