Hi,
Would really appreciate some help on the image uploading portion.
It is an image upload page of an album where the uploading portion will be uploaded to the folder of the album.
While the image is being uploaded, it will be resized and save a thumbnail. For the thumbnail folder, i had try to hard-code it and it is able to save to the folder while the main image is supposed to save into the album folder, but it can seem to locate the album folder.
Had try to call out the id from the previous page but it doesn't seem to call from there!
Tks and appreciate for the help
This is the uploading form:
<legend><h2>Upload to <?php echo $row_album['album_name']; ?> </h2></legend>
<form name="uploadimage" action="p_uploadPhoto2.php" method="post" enctype="multipart/form-data">
<input type="file" name="image" /><br>
<input type="submit" name="submit" value="Upload" />
</form>
This is the processing portion.
<?php
session_start();
$message = "<strong>You have to login to assess this page! </strong><br><a href ='index.php'> Click here </a> to login!";
if(isset($_SESSION['login_name'])){
require_once "../dbConnect.php";
$id = $_GET['id'];
$esp_id = mysqli_real_escape_string($redConnect, $id);
$query = "SELECT * FROM red_photoalbum WHERE album_id ='$esp_id'";
$result = mysqli_query($redConnect, $query) or die(mysqli_error($redConnect));
$row_album = mysqli_fetch_array($result);
define ("MAX_SIZE","100");
define ("WIDTH","150");
define ("HEIGHT","100");
function make_thumb($img_name,$filename,$new_w,$new_h){
$ext=getExtension($img_name);
if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
$src_img=imagecreatefromjpeg($img_name);
if(!strcmp("png",$ext))
$src_img=imagecreatefrompng($img_name);
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
$ratio1=$old_x/$new_w;
$ratio2=$old_y/$new_h;
if($ratio1>$ratio2){
$thumb_w=$new_w;
$thumb_h=$old_y/$ratio1;
}else{
$thumb_h=$new_h;
$thumb_w=$old_x/$ratio2;
}
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
// output the created image to the file. Now we will have the thumbnail into the file named by $filename
if(!strcmp("png",$ext))
imagepng($dst_img,$filename);
else
imagejpeg($dst_img,$filename);
//destroys source and destination images.
imagedestroy($dst_img);
imagedestroy($src_img);
}
function getExtension($str){
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CMS Upload Photo</title>
<link href="stylesheet/adminStyle.css" rel="stylesheet" type="text/css" />
</head>
<body><?php include ("topBanner.php");?>
<div id="midContainer">
<div id="midLeftContainer">
<strong><em>Welcome Red Dynasty Administrator,</em></strong>
<div id="leftNav"> <?php include ("leftNav.php");?>
</div>
</div>
<div id="midRightContainer">
<?php
if(isset($_POST['submit'])){
$image=$_FILES['image']['name'];
if ($image){
$filename = stripslashes($_FILES['image']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png")){
echo '<h1>Unknown extension!</h1>';
$errors=1;
}else{
$size=getimagesize($_FILES['image']['tmp_name']);
$sizekb=filesize($_FILES['image']['tmp_name']);
if ($sizekb > MAX_SIZE*1024){
echo '<h1>You have exceeded the size limit!</h1>';
$errors=1;
}
$row_album = mysqli_fetch_array($result);
$image_name=time().'.'.$extension;
$newname="../assets/imageGallery/".$row_album['album_name']."/".$image_name;
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied) {
echo '<h1>Copy unsuccessfull!</h1>';
$errors=1;
}
else
{
$thumb_name="../assets/imageGallery/test/thumb/".$image_name;
$thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT);
}
}
}
}
if(isset($_POST['Submit']) && (!$errors)){
echo "<h1>Thumbnail created Successfully!</h1>";
echo '<img src="'.$thumb_name.'">';
}?>
</div>
</div>
<?php }else{
echo "<center><br><br>";
echo $message;
echo "</center>";
} ?>
<div id="clearBoth">
</div>
</body>
</html>