I'm trying to get a file upload to work and it's not happening. Here's my
form code...
echo '<form enctype="multip art/form-data" action="catalog ue.php"
method="post">
<input type="hidden" name="MAX_FILE_ SIZE" value="204800">
<table border="0" width="100%">
<tr>
<td width=100%>
<center>
<table border="0">
<tr>
<td>
<font face="Tahoma">A dd Subcategory</font>
</td>
<td>
<input name="subcat" type="text" style="width:22 7px">
</td>
</tr>
<tr>
<td>
<font face="Tahoma">t o Category</font>
</td>
<td>';
$result=mysql_q uery("select * from category");
echo '<select name="category" style="width:22 7px" size="1">';
for($i=0;$i<mys ql_num_rows($re sult);$i++)
{
$row=mysql_fetc h_array($result );
echo '<option
value="'.$row["category"].'">'.$row["descriptio n"].'</option>';
}
echo '</select>
</td>
</tr>
<tr>
<td>
<font face="Tahoma">w ith picture</font>
</td>
<td>
<input type="file" name="userfile" >
</td>
</tr>
</table>
</center>
</td>
</tr>
</table>
<input type="hidden" name="action" value="2">
<p align="center"> <input type="submit" value="Add
Subcategory"></p></form>';
Which displayes the form perfectly well. However, the script which captures
the form always seems to have a completly empty userfile variable. Here's my
processing script:
$userfile=$_FIL E['userfile']['tmp_name'];
$userfile_name= $_FILE['userfile']['name'];
$userfile_size= $_FILE['userfile']['size'];
$userfile_type= $_FILE['userfile']['type'];
$userfile_error =$_FILE['userfile']['error'];
if(!$_REQUEST['subcat'])
{
echo '<p align="center"> <font face="Tahoma" color="#FF0000" ><b>
No Category was Entered</b></font></p>';
}
else if($userfile_er ror > 0)
{
switch($userfil e_error)
{
case 1: echo "Picture too large, max size is 200kb"; break;
case 2: echo "Picture too large, max size is 200kb"; break;
case 3: echo "Picture failed to upload"; break;
case 4: echo "No Picture"; break;
}
}
else
{
$categoryid = $_REQUEST['category'];
$subcat = $_REQUEST['subcat'];
$result=mysql_q uery("select * from category where
category=$categ oryid");
$row=mysql_fetc h_array($result );
echo '<p align="center"> <font face="Tahoma">' ;
echo $subcat.' was added to '.$row["descriptio n"];
echo '</font></p>';
$result=mysql_q uery("insert into subcategory (subcategory, category,
description) values (null, $categoryid, '$subcat')");
}
The script never processes the error section, the file doesn't get uploaded
but the rest of the form works fine. If a file is specified or not in the
other script the rest always works fine. Any help would be greatly
appreciated!
Phil
form code...
echo '<form enctype="multip art/form-data" action="catalog ue.php"
method="post">
<input type="hidden" name="MAX_FILE_ SIZE" value="204800">
<table border="0" width="100%">
<tr>
<td width=100%>
<center>
<table border="0">
<tr>
<td>
<font face="Tahoma">A dd Subcategory</font>
</td>
<td>
<input name="subcat" type="text" style="width:22 7px">
</td>
</tr>
<tr>
<td>
<font face="Tahoma">t o Category</font>
</td>
<td>';
$result=mysql_q uery("select * from category");
echo '<select name="category" style="width:22 7px" size="1">';
for($i=0;$i<mys ql_num_rows($re sult);$i++)
{
$row=mysql_fetc h_array($result );
echo '<option
value="'.$row["category"].'">'.$row["descriptio n"].'</option>';
}
echo '</select>
</td>
</tr>
<tr>
<td>
<font face="Tahoma">w ith picture</font>
</td>
<td>
<input type="file" name="userfile" >
</td>
</tr>
</table>
</center>
</td>
</tr>
</table>
<input type="hidden" name="action" value="2">
<p align="center"> <input type="submit" value="Add
Subcategory"></p></form>';
Which displayes the form perfectly well. However, the script which captures
the form always seems to have a completly empty userfile variable. Here's my
processing script:
$userfile=$_FIL E['userfile']['tmp_name'];
$userfile_name= $_FILE['userfile']['name'];
$userfile_size= $_FILE['userfile']['size'];
$userfile_type= $_FILE['userfile']['type'];
$userfile_error =$_FILE['userfile']['error'];
if(!$_REQUEST['subcat'])
{
echo '<p align="center"> <font face="Tahoma" color="#FF0000" ><b>
No Category was Entered</b></font></p>';
}
else if($userfile_er ror > 0)
{
switch($userfil e_error)
{
case 1: echo "Picture too large, max size is 200kb"; break;
case 2: echo "Picture too large, max size is 200kb"; break;
case 3: echo "Picture failed to upload"; break;
case 4: echo "No Picture"; break;
}
}
else
{
$categoryid = $_REQUEST['category'];
$subcat = $_REQUEST['subcat'];
$result=mysql_q uery("select * from category where
category=$categ oryid");
$row=mysql_fetc h_array($result );
echo '<p align="center"> <font face="Tahoma">' ;
echo $subcat.' was added to '.$row["descriptio n"];
echo '</font></p>';
$result=mysql_q uery("insert into subcategory (subcategory, category,
description) values (null, $categoryid, '$subcat')");
}
The script never processes the error section, the file doesn't get uploaded
but the rest of the form works fine. If a file is specified or not in the
other script the rest always works fine. Any help would be greatly
appreciated!
Phil
Comment