0

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>
3
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by ujjval dave
1

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.

1

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.

Edited by paulrajj: n/a

Votes + Comments
because he solved my question.
0

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

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.