0

Hi Friends

i am trying to upload the photos in my dynamic place through my script. my path will be specified below

$uploaddir = ../gallery/categoryname/name/

when i was trying to upload the photo is not moved in the above path. unfortunatelly is it moved to

../gallery/

Please help me to solve the issue

<?php
include('../conn.php');

	$id = $_GET['galleryid'];
	//echo $id;

	$qry="select * from gallery where gallery_id='$id'";
	//echo $qry;
	$res=mysql_query($qry,$conn);
	$row=mysql_fetch_array($res);
	//$uploaddir = '../gallery'.'/'.$row["gallery_cat"].'/'.$row["gallery_name"].'/'; 
	//echo $uploaddir;
	
	$path = '../gallery/';
	
	$gallery_cat = $row['gallery_cat'].'/';
	
	$gallery_name = $row['gallery_name'].'/';
	
	echo $uploaddir = $path.$gallery_cat.$gallery_name;
?>

<!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" dir="ltr">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Upload image</title>
<script type="text/javascript" src="js/jquery-1.3.2.js" ></script>
<script type="text/javascript" src="js/ajaxupload.3.5.js" ></script>
<link rel="stylesheet" type="text/css" href="./styles.css" />
<script type="text/javascript" >
	$(function(){
		var btnUpload=$('#upload');
		var status=$('#status');
		new AjaxUpload(btnUpload, {
			action: 'upload-filenew.php',
			name: 'uploadfile',
			onSubmit: function(file, ext){
				 if (! (ext && /^(jpg|png|jpeg)$/.test(ext))){ // Allowed extensions 
					status.text('Only JPG or PNG images allowed');
					return false;
				}
				status.text('Uploading...');
			},
			onComplete: function(file, response){
				//When ready, remove statuss
				status.text('Success');
				//Uploaded file added to list
				if(response==="success"){
					$('<li></li>').appendTo('#files').html('<img src="../gallery/<?php echo $row["gallery_cat"]?>/<?php echo $row["gallery_name"]?>/'+file+'" alt="" /><br />'+file).addClass('success');
				} else{
					$('<li></li>').appendTo('#files').text(file).addClass('error');
				}
			}
		});
		
	});

	$(function() {
		$(".delete").click(function() {
			var upldimages = $(this).parent();
			var id = $(this).attr("id");
			var string = 'id='+ id ;
	
			$.ajax({
	   			type: "POST",
				URL: "delete.php",
   				data: string,
	   			cache: false,
   				success: function(){
					upldimages.fadeOut('slow', function() {$(this).remove();});
  				}
			});
			return false;
		});
	});
</script>

</head>
<body>
<div id="mainbody" >
	<div id="upload" >
       	<span>Upload image</span>
    </div>
    <span id="status"></span>
	<ul id="files"></ul>
</div>
<div class="line"></div>

</body>

upload-filenew.php

<?php
include('../conn.php');
$path = '../gallery/';
$id = $_GET['galleryid'];

	$qry="select * from gallery where gallery_id='".$_REQUEST["galleryid"]."'";
	//echo $qry;
	$res=mysql_query($qry,$conn);
	$row=mysql_fetch_array($res);
	
	$gallery_cat = $row['gallery_cat'].'/';
	
	$gallery_name = $row['gallery_name'].'/';

$filename = $_FILES['uploadfile']['name'];

$uploaddir = $path.$gallery_cat.$gallery_name;
 
$file = $uploaddir . basename($filename); 

if (isset($filename)) { 
	move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file);
	mysql_query("INSERT INTO tablename (id, categoryname, imagename, date) VALUES ($id, $categoryname, $imagename, now());") or die(mysql_error()); 
	echo "success"; 
} else {
	echo "error";
}
?>

Edited by rpv_sen: n/a

1
Contributor
1
Reply
4
Views
6 Years
Discussion Span
Last Post by rpv_sen
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.