Upload problems

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I intend to upload documents (file_up), categorize them in 4 main
categories (k_cat), have additional sub-categories (lec_cat) just for
querying and getting sub-categorized output of the files when listed
with date (dato_inn) and the submitters details "uploaded_by".

But my script will not work. Anyone clever out there seeing what's

This is my upload form, the script at the bottom:

<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>
<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>
<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>
</td></tr><tr><td width = "150"><div align="right">
  <label for="lev_cat">Choose sub category </label>
<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>
<td><input id="dato_inn" name="dato_inn" type="text" size="25"
value="" maxlength="255"></td></tr><tr><td width = "150"><div
  <label for="uploaded_by">Uploaded by:</label>
<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>

//this is added.php

$file_up = $_POST['file_up'];
$k_cat = $_POST['k_cat'];
$lev_cat = $_POST['lev_cat'];
$dato_inn = $_POST['dato_inn'];
$uploaded_by = $_POST['uploaded_by'];

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',

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

if ($results)
echo "Details added.";

Re: Upload problems

could be a lot of things,

mostly when such a thing happen in my case it's a permission problem, make  
sure that the directory where you upload the files can be written to by PHP.

another less common case would be that your host disabled the use of the  
functions used to take an uploaded file and copy it somewhere else.

Hope this helps.

Quoted text here. Click to load it

Site Timeline