File Uploads: File Isn't Set
Posted: Fri Jul 17, 2009 11:21 pm
Hey, I'm new here. I'm working on a photo gallery project for a student group so I can learn PHP and about server-side scripting. This particular section has been giving me nothing but trouble.
My current problem: I think my problem is that my files aren't set. I don't think they're posted correctly.
So, here is the first part of the upload process: upload_pic.php.
<?php include 'config.inc.php'; ?>
<html>
<head>
<title>Upload Pictures to Album</title>
</head>
<body>
<form enctype="multipart/form-data" action="describe_pic.php" method="POST">
<h1>Upload Pictures to Album</h1>
<br / >
Select Album:
<select name="album">
<?php
$result_album = mysql_query('SELECT * FROM photo_album') or die(mysql_error());
while($row_album = mysql_fetch_array($result_album))
{
echo "<option value=".$row_album['aid'].">".$row_album['title']."</option>";
}
?>
</select>
<br / >
<br / >
Browse for Photos:
<br / >
<input type="hidden" name="MAX_FILE_SIZE" value="5242880" />
<input name="pic1" type="file" /><br />
<input name="pic2" type="file" /><br />
<input name="pic3" type="file" /><br />
<input name="pic4" type="file" /><br />
<input name="pic5" type="file" /><br />
Size Limit: 5 MB/picture
<br / >
Accepted Picture Formats: JPG
<br / >
<br / >
<input type="submit" value="Submit" name="submit"/>
</form>
</body>
</html>
Here is the second and incomplete part of the chain, describe_pic.php. I've only pasted the top part. How can I post files? Apparently they aren't being "set":
<?php include 'config.inc.php'; ?>
<html>
<head>
<title>Describe Pictures</title>
</head>
<body>
<?php
// script stolen from event pic uploader
$details .= "> Processing Images...<br/>";
// get aid
$album = $_POST['album'];
$sql = "SELECT aid FROM photo_album WHERE title='$album'";
$aid = mysql_query($sql) or die(mysql_error());
// get gid associated w/ aid
$gid = mysql_query("SELECT gid FROM photo_album WHERE aid='$aid'") or die(mysql_error());
// find out which upload slots had pictures in them
$set_pic_array = array(); // store set pics here
$accepted_pic_array = array(); // store accepted pics here. will be used later
//for ($i=1; $i<=5; $i++)
// {
// if (isset($_FILE['pic'.$i]))
// array_push($set_pic_array, $_FILE['pic'.$i]); // if slot contained a photo, add it to the $set_pic_array
// }
// DEBUG
echo "aid: $aid";
echo "<br / >";
echo "gid: $gid";
echo "<br / >";
//foreach($set_pic_array as $contents)
// {
// echo "$contents";
// }
echo "<br / >";
$pic_single = 'pic1';
$set = var_dump(isset($_FILE[$pic_single])); // is pic1 set?
echo "set or no? $set";
echo "<br / >";
//
// check each pic's validity
// foreach ($set_pic_array as $pic_single) {
$results = mysql_query("SELECT * FROM photo_pic WHERE aid='$aid'") or die(mysql_error()); // get info about this pic's album AND help generate new pid
$pid = mysql_num_rows($results) or die(mysql_error()); // assign pid based on # entries in album
//DEBUG
echo "pid: $pid";
Thanks.
My current problem: I think my problem is that my files aren't set. I don't think they're posted correctly.
So, here is the first part of the upload process: upload_pic.php.
<?php include 'config.inc.php'; ?>
<html>
<head>
<title>Upload Pictures to Album</title>
</head>
<body>
<form enctype="multipart/form-data" action="describe_pic.php" method="POST">
<h1>Upload Pictures to Album</h1>
<br / >
Select Album:
<select name="album">
<?php
$result_album = mysql_query('SELECT * FROM photo_album') or die(mysql_error());
while($row_album = mysql_fetch_array($result_album))
{
echo "<option value=".$row_album['aid'].">".$row_album['title']."</option>";
}
?>
</select>
<br / >
<br / >
Browse for Photos:
<br / >
<input type="hidden" name="MAX_FILE_SIZE" value="5242880" />
<input name="pic1" type="file" /><br />
<input name="pic2" type="file" /><br />
<input name="pic3" type="file" /><br />
<input name="pic4" type="file" /><br />
<input name="pic5" type="file" /><br />
Size Limit: 5 MB/picture
<br / >
Accepted Picture Formats: JPG
<br / >
<br / >
<input type="submit" value="Submit" name="submit"/>
</form>
</body>
</html>
Here is the second and incomplete part of the chain, describe_pic.php. I've only pasted the top part. How can I post files? Apparently they aren't being "set":
<?php include 'config.inc.php'; ?>
<html>
<head>
<title>Describe Pictures</title>
</head>
<body>
<?php
// script stolen from event pic uploader
$details .= "> Processing Images...<br/>";
// get aid
$album = $_POST['album'];
$sql = "SELECT aid FROM photo_album WHERE title='$album'";
$aid = mysql_query($sql) or die(mysql_error());
// get gid associated w/ aid
$gid = mysql_query("SELECT gid FROM photo_album WHERE aid='$aid'") or die(mysql_error());
// find out which upload slots had pictures in them
$set_pic_array = array(); // store set pics here
$accepted_pic_array = array(); // store accepted pics here. will be used later
//for ($i=1; $i<=5; $i++)
// {
// if (isset($_FILE['pic'.$i]))
// array_push($set_pic_array, $_FILE['pic'.$i]); // if slot contained a photo, add it to the $set_pic_array
// }
// DEBUG
echo "aid: $aid";
echo "<br / >";
echo "gid: $gid";
echo "<br / >";
//foreach($set_pic_array as $contents)
// {
// echo "$contents";
// }
echo "<br / >";
$pic_single = 'pic1';
$set = var_dump(isset($_FILE[$pic_single])); // is pic1 set?
echo "set or no? $set";
echo "<br / >";
//
// check each pic's validity
// foreach ($set_pic_array as $pic_single) {
$results = mysql_query("SELECT * FROM photo_pic WHERE aid='$aid'") or die(mysql_error()); // get info about this pic's album AND help generate new pid
$pid = mysql_num_rows($results) or die(mysql_error()); // assign pid based on # entries in album
//DEBUG
echo "pid: $pid";
Thanks.