What script do I need for ths project? (Upload images script?)
10-24-09, 01:32 PM
New Member
Join Date: Jul 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
What script do I need for ths project? (Upload images script?)
I am working on a site for a tow truck company. They would like a script that has a back-end where employees can upload pictures of impounded cars and input a description about the vehicle. '
The script would auto resize the picture if necessary and populate a simple table on the site. The final look would be a list of cars with a brief description on the site and a date stamp.
What script is out there that can do this or were can I inquire about this from another JAVA/PERL expert?
If anyone can point me in the right direction or offer some quick services to help out I have a paypal verified acct. I can pay a little for this help.
10-24-09, 07:54 PM
Level II Curmudgeon
Join Date: Dec 2004
Posts: 3,027
Thanks: 14
Thanked 35 Times in 33 Posts
There are lots of upload scripts that will also resize an image. If you search Hotscripts you'll find quite a few.
10-30-09, 05:25 PM
Aspiring Coder
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
You could modify this to fit your needs, it is basic and easy to understand. More sanitation and validation could be used.
PHP Code:
$setWidth = 300 ;
$setHeight = 300 ;
if(isset( $_POST [ 'upload' ])) {
$message = mysql_real_escape_string ( strip_tags ( $_POST [ 'message' ]));
$hobby = mysql_real_escape_string ( strip_tags ( $_POST [ 'hobby' ]));
if( $_FILES [ "file" ][ "size" ] > 900000 ) { $content .= "File is to large, submit a smaller image!" ; }
elseif(empty( $_FILES [ "file" ][ "name" ])) { $content .= "No File Uploaded!" ; }
else
{
if ((( $_FILES [ "file" ][ "type" ] == "image/gif" )
|| ( $_FILES [ "file" ][ "type" ] == "image/jpeg" )
|| ( $_FILES [ "file" ][ "type" ] == "image/pjpeg" )
|| ( $_FILES [ "file" ][ "type" ] == "image/png" )
|| ( $_FILES [ "file" ][ "type" ] == "image/jpg" )
|| ( $_FILES [ "file" ][ "type" ] == "image/x-png" ))
&& ( $_FILES [ "file" ][ "size" ] < 900000 ))
{
$image = str_replace ( ' ' , '_' , $_FILES [ "file" ][ "name" ]);
$image = str_replace ( "'" , '' , $image );
if ( $_FILES [ "file" ][ "error" ] > 0 )
{
$content .= "Return Code: " . $_FILES [ "file" ][ "error" ] . "<br />" ;
}
else
{
if ( file_exists ( "images/" . $_FILES [ "file" ][ "name" ]))
{
$content .= $_FILES [ "file" ][ "name" ] . " already exists. Upload cancelled!<br/>Image path saved." ;
}
else
{
$uploadedfile = $_FILES [ "file" ][ "tmp_name" ];
$size = getimagesize ( $uploadedfile );
$type = $size [ 'mime' ];
$width = $size [ 0 ];
$height = $size [ 1 ];
if( $height > $setHeight || $width > $setWidth )
{
$newwidth = $setWidth ;
$newheight =( $height / $width )* $setWidth ;
$tmp = imagecreatetruecolor ( $newwidth , $newheight );
$filename = "images/ $image " ;
if( $size [ 2 ] == IMAGETYPE_GIF )
{
$src = imagecreatefromgif ( $uploadedfile );
imagecopyresampled ( $tmp , $src , 0 , 0 , 0 , 0 , $newwidth , $newheight , $width , $height );
imagegif ( $tmp , $filename , 100 );
}
elseif( $size [ 2 ] == IMAGETYPE_JPEG )
{
$src = imagecreatefromjpeg ( $uploadedfile );
imagecopyresampled ( $tmp , $src , 0 , 0 , 0 , 0 , $newwidth , $newheight , $width , $height );
imagejpeg ( $tmp , $filename , 100 );
}
elseif( $size [ 2 ] == IMAGETYPE_PNG )
{
$src = imagecreatefrompng ( $uploadedfile );
imagecopyresampled ( $tmp , $src , 0 , 0 , 0 , 0 , $newwidth , $newheight , $width , $height );
imagepng ( $tmp , $filename , 9 );
}
$content .= "Image has been resized to $newwidth X $newheight <br/>" ;
imagedestroy ( $src );
imagedestroy ( $tmp );
}
else
{
move_uploaded_file ( $uploadedfile , "images/ $image " );
}
}
}
}
else { $content .= "Invalid file" ; }
}
$image = mysql_real_escape_string ( $image );
$imageUpload = (isset( $image )) ? ",`image`= ' $image ' " : NULL ;
$update = "UPDATE `bio` SET `message` = ' $message ', `hobby` = ' $hobby ' $imageUpload WHERE `id` = ' $id '" ;
mysql_query ( $update ) or die( mysql_error ());
}
You will need to change the Database lines, but I left those in to show you a working script. Don't worry, it is from an old project. Use it as you will.
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes
Linear Mode
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off