this is the upload script that goes with it:
<---------select_item.php------------>
<?php
session_start();
require_once('main_fns.php');
?>
<table width="840" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="840" valign="top" align="center" height="600">
<font face="verdana, arial" size="2" color="#1f3145">
Add a picture & title.<p>
<form enctype="multipart/form-data" action="upload_pic.php" method="post">
<br>
<input type="hidden" name="nickname" size="20" value="<?php $_POST['nickname'] ?>"><p>
Select a Photo<br>
<input type="file" name="upfile">
<p>
<input type="submit" name="submit" value="Add Item">
<input type="reset" name="reset" value="Reset">
</form>
</font>
</td>
</tr>
</table>
<?php
do_html_footer();
?>
<-------upload_pic.php-------------->
<?php
session_start();
require_once('main_fns.php');
// Limits file types
$file_types = array(
'image/pjpeg' => 'jpg',
'image/jpeg' => 'jpg',
'image/gif' => 'gif',
'image/bmp' => 'bmp'
);
$nickname = $_POST['nickname'];
$max_size = 2000000;
$filesize = $_FILES['upfile']['size'];
$filetype = $_FILES['upfile']['type'];
$upload_dir = $_SERVER['DOCUMENT_ROOT'] . "/Project1/images/"; //change directory to the path to your folder
if ($filesize > $max_size){
echo ("File is too big.");
exit;
}
if (!array_key_exists($filetype, $file_types)) {
echo ("File is wrong type");
exit;
}
else
{
$new_file = substr(sha1(rand(10, time())), 0, 8) . '.' . $file_types[$filetype];
if (move_uploaded_file($_FILES['upfile']['tmp_name'], $upload_dir . $new_file)) {
$filename=$new_file;
// add your connection strings here
$conn = db_connect();
$query = "UPDATE profile
SET image = '$filename'
WHERE nickname ='$_POST[nickname]'";
$result=mysql_query($query, $conn);
}
}
echo "<p>File Uploaded</p>";
echo "<a href=\"edit_profile.php\">Back</a>"
?>