Forum Moderators: coopster

Message Too Old, No Replies

Problem with upload script

upload file and metadata

         

Awful newbie

9:23 pm on Apr 11, 2007 (gmt 0)

10+ Year Member



My goal is to upload documents to my server and categorize them (and add som meta data to each document). Four main categories (k_cat) and several sub-categories (lev_cat)-in order to separate better.
I think my upload form is good, but my processing script (added.php) doesn't seem to work. I don't know what I have done wrong.

First my processing script, and at the bottom my upload form.

<?php
// this is "added.php"

include("connect.php");
$file_up = $_POST['file_up']; //the file chosen for upload
$k_cat = $_POST['k_cat']; //the main categories
$lev_cat = $_POST['lev_cat']; //the sub-categories
$dato_inn = $_POST['dato_inn']; //this mean date added
$uploaded_by = $_POST['uploaded_by']; //name of uploader

if $_POST['file_up'] ==<1 & $_POST['k_cat']=='category_1' {
move_uploaded_file ($_FILES['file_up'] ['tmp_name'],
"../uploads/category_1/{$_FILES['file_up'] ['name']}")
}

elseif $_POST['file_up'] ==<1 & $_POST['k_cat']=='category_2' {
move_uploaded_file ($_FILES['file_up'] ['tmp_name'],
"../uploads/category_2/{$_FILES['file_up'] ['name']}")
}
elseif $_POST['file_up'] ==<1 & $_POST['k_cat']=='category_3' {
move_uploaded_file ($_FILES['file_up'] ['tmp_name'],
"../uploads/category_3/{$_FILES['file_up'] ['name']}")
}
elseif $_POST['file_up'] ==<1 & $_POST['k_cat']=='category_4' {
move_uploaded_file ($_FILES['file_up'] ['tmp_name'],
"../uploads/category_4/{$_FILES['file_up'] ['name']}")
}

$query = "INSERT INTO lev_database (id, file_up, k_cat, lev_cat, dato_inn, uploaded_by)
VALUES ('', '$file_up', '$k_cat', '$lev_cat', '$dato_inn', '$uploaded_by')";

$results = mysql_query($query) or die
("Could not execute query : $query." . mysql_error());

if ($results)
{
echo "Document and data added.";
}
mysql_close();
?>

Here is the form:
<form enctype="multipart/form-data" id="uploadform" action="added.php" method="post" name="uploadform">
<table width="90%" border="0" cellspacing="2" cellpadding="0"><tr><td width = "150"><div align="right">
<label for="fil">Choose file to upload: </label>
</div></td>
<td><input id="file_up" name="file_up" type="file" size="50" value="" maxlength="255"></td></tr><tr><td width = "150"><div align="right">
<label for="k_cat">Choose main category: </label>
</div></td>
<td><select name="k_cat" id="k_cat">
<option value="Category_1">Category_1</option>
<option value="Category_2">Category_2</option>
<option value="Category_3">Category_3</option>
<option value="Category_4">Category_4</option>
</select>
</td></tr><tr><td width = "150"><div align="right">
<label for="lev_cat">Choose sub category </label>
</div></td>
<td><select name="lev_cat" id="lev_cat">
<option value="Category_1_Sub_1">Category_1_Sub_1</option>
<option value="Category_1_Sub_2">Category_1_Sub_2</option>
<option value="Category_1_Sub_3">Category_1_Sub_3</option>
<option value="Category_1_Sub_4">Category_1_Sub_4</option>
<option value="Category_2_Sub_1">Category_2_Sub_1</option>
<option value="Category_2_Sub_2">Category_2_Sub_2</option>
<option value="Category_2_Sub_3">Category_2_Sub_3</option>
<option value="Category_2_Sub_4">Category_3_Sub_4</option>
</select></td></tr><tr><td width = "150"><div align="right">
<label for="dato_inn">Date uploaded</label>
</div></td>
<td><input id="dato_inn" name="dato_inn" type="text" size="25" value="" maxlength="255"></td></tr><tr><td width = "150"><div align="right">
<label for="uploaded_by">Uploaded by:</label>
</div></td>
<td><input id="uploaded_by" name="uploaded_by" type="text" size="25" value="" maxlength="255"></td></tr><tr><td width="150"></td><td>
<input type="submit" name="submitButtonName" value="Add file and entry to DB"></td>
</tr></table>
</form>

whoisgregg

9:28 pm on Apr 11, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In what way does it not work? :) Also, are there any error messages? Add this line to the top of any script that is misbehaving to aid in bebugging:

error_reporting(E_ALL);