Upload Image & Compress Image Size

Upload Image & Compress Image Size

HTML Code For File Uploading

<form action=”upload.php” method=”post” name=”video_upload” enctype=”multipart/form-data”>
<input name=”new_image” id=”new_image” size=”30″ type=”file” multiple=”true” />
<input type=”submit” value=”submit” name=”submit” />
</form>

 

File Name upload.php
<?php

if (isset ($_FILES[‘new_image’])){
$imagename = $_FILES[‘new_image’][‘name’];
$source = $_FILES[‘new_image’][‘tmp_name’];
$type=$_FILES[‘new_image’][‘type’];

$idate=$_REQUEST[‘idate’];

if(($_FILES[‘new_image’][‘type’]==’image/jpeg’) ||
($_FILES[‘new_image’][‘type’]==’image/png’)||
($_FILES[‘new_image’][‘type’]==’image/bmp’)||
($_FILES[‘new_image’][‘type’]==’image/tiff’)||
($_FILES[‘new_image’][‘type’]==’image/gif’))
{
$target = “../upload/”.$imagename;
move_uploaded_file($source, $target);

$imagepath = $imagename;
$save = “../upload/” . $imagepath; //This is the new file you saving
$file = “../upload/” . $imagepath; //This is the original file

list($width, $height) = getimagesize($file) ;

$tn = imagecreatetruecolor($width, $height) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $width, $height, $width, $height) ;

imagejpeg($tn, $save, 75) ;

$save = “../upload/sml_” . $thumbfile=$imagepath; //This is the new file you saving
$file = “../upload/” . $fullimage=$imagepath; //This is the original file

list($width, $height) = getimagesize($file) ;

$modwidth = 155;

$diff = $width / $modwidth;

$modheight = 130;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;

imagejpeg($tn, $save, 100) ;
“Large image: <img src=’images/”.$imagepath.”‘><br>”;
“Thumbnail: <img src=’images/sml_”.$imagepath.”‘>”;

}
}
else
{
echo “Please upolad .jpg, .png image file”;
}
?>

0

How To Connect Database in PHP

How To Connect Database in PHP

<?php
$host=”localhost”;
$user=”root”;
$pass=””;
$database=”databasename”;

$conn=mysql_connect($host,$user,$pass);
mysql_select_db($database);

$_GET = array_map(‘trim’, $_GET);
$_COOKIE = array_map(‘trim’, $_COOKIE);
if(get_magic_quotes_gpc()):
$_GET = array_map(‘stripslashes’, $_GET);
$_POST = array_map(‘stripslashes’, $_POST);
$_COOKIE = array_map(‘stripslashes’, $_COOKIE);
$_REQUEST = array_map(‘stripslashes’, $_REQUEST);
endif;

//$sql = ‘SELECT * FROM create_user’;
//
//$result=mysql_query($sql,$conn);
//
//    while($row = mysql_fetch_assoc($result)) {
//
//       echo $row[‘_company’];
//      }
?>

0