Greetings all,
I'm trying to write a CMS for a photo gallery, and I worked out that the best way would be to upload the images to a directory and have a mysql table to store the relative location of the images for later use.

I have 1 problem, which I believe causes the file not to be uploaded.

<?php
session_start();
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
include('../functions2.php');
include('dbconfig.php');


$file=$_POST['upload'];
if ($_SESSION['loggedIn']==1)
{
	if (isset($file))
	{
		$conn=mysql_connect($host,$username,$password) or die(mysql_error());
		mysql_select_db("$db_name")or die("cannot select DB");
		$uploadDate=date("d/m/y : H:i:s", time());
		
		$target_path = "../gallery/";
		$target_path = $target_path . basename($_FILES['photo']['name']);
		$galleryId=$_POST['photoGallery'];
		
		if(move_uploaded_file($_FILES['photo']['tmp_name'], $target_path))
		{
			$sql="INSERT INTO tblPhotoGallery (galleryId, location, uploadDate, show) VALUES ('$galleryId','$target_path','$uploadDate','1')";
			echo $sql;
			mysql_query($sql) or die(mysql_error());
		}
	}
	
	else
	{
		echo "No upload";
	}
	?>
	
	<a href="gallery.php">Image Gallery</a>
    <table bgcolor="#FFFF99">
    <tr bgcolor="#FFFFCC"><td>Select</td><td>Name</td><td>Gallery</td><td>Upload Date</td></tr>
    <?php
	$conn=mysql_connect($host,$username,$password) or die(mysql.error());
	mysql_select_db("$db_name")or die("cannot select DB");
	$sql="SELECT * FROM tblPhotoGallery,tblGallery ORDER BY pictureId";
	$result=mysql_query($sql);
	
	$row=mysql_fetch_array($result);
	while($row = mysql_fetch_array($result))
	{?>
		<tr><td><?php echo $row['show']; ?></td><td><?php echo $row['name']; ?></td><td><?php echo $row['uploadDate']; ?></td></tr>
    <?php	
	}
	?>
    </table>
    <h1>Upload Picture</h1>
    <form action="gallery.php" method="post" enctype="multipart/form-data">
    <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
    <label for="photo">Select file:</label><input type="file" name="photo" id="photo" />
    <label for="photoGallery">Gallery:</label><select name="photoGallery">
	<?php
	$sql2="SELECT * FROM tblgallery ORDER BY galleryId";
	$result2=mysql_query($sql2);
	$row2=mysql_fetch_array($result);
	while($row2 = mysql_fetch_array($result2))
	{
		print '<option value="'.$row2['galleryId'].'">'.$row2['name'].'</option>';
    }
	?>
    </select>
    <input type="submit" name="upload" value="Upload photo"/>
    </form>
<?php	
}
?>

Error:

Notice: Undefined index: upload in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\newsite\admin\gallery.php on line 9

So basicly, the CMS is in the /admin folder, and I would like the images stored in the /gallery folder.

What do I need to do to fix this undefined index?

You get this notice if the form is not posted and the 'upload' input is not found. You can avoid it like this:

if (isset($_POST['upload']))
  $file=$_POST['upload'];
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.