hi everyone,
i have a problem in my php code.i hope anyone of you can help me in this problem.
i have a problem for image uploading in particular folder.
my code works but this will upload images in root directory called as 'upimg'.
i want to upload images into particular directory(variable name as $dirna).
i m giving you my code.so pls help me.

<?php
if(isset($_SESSION['alnamae']))
{
	$alaname = $_SESSION['alnamae'];
}
else
{
	header("Location: addimg.php");
}
if(isset($_SESSION['dirna']))
{
	$dirna = $_SESSION['dirna'];
	//echo $dirna;
}
else
{
header("Location: addimg.php");
}
?>
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>

<head><title>Multiple image upload</title>

</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<?php
error_reporting(0);
	$path = "upimg/" . $dirna . "/";
	echo $path;
while(list($key,$value) = each($_FILES['images']['name']))
		{
			if(!empty($value))
			{
				$filename = $value;
					$filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line

					$add = $path."$filename";
					//$add = "upimg/$filename";
                       //echo $_FILES['images']['type'][$key];
			     // echo "<br>";
					copy($_FILES['images']['tmp_name'][$key], $add);
					//chmod("$add",0777);
			

			}
		}


?>
 
</body>

</html>

Hello Ujjval
I think you should check for the permission to the directory called by '$dirna'.
use chmod to check $dirna. You should check $path = "upimg/".$dirna;
chmod ($path,0777);
then use $add=$path."/".$filename
Hope it will work.

You need to check whether any value is assigned to a varible $dirna or not. Though you are setting value to $dirna through session, you need to start session in top of this page

session_start()

hope this helps.

commented: because he solved my question. +1

hey paulrajj thanks for your golden help.
this was a really silly mistake.
now my question is solved.
thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.