hi everyone,
Im pretty new to PHP coding and im having trouble writing the code to upload pictures to a mysql database.
the code i have so far is:
The upload form:
<p>Upload Image</p>
<form action="picupload.php" method="post" enctype="multipart/form-data">
<table>
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="picfile" type="file" id="picfile">
</td>
<td>
<input type="submit" name="submit" value="Submit" />
</td>
</tr>
</table>
</form>
Then the processing on the next page:
<?php
if(isset($_POST['upload']) && $_FILES['picfile']['size'] > 0)
{
$name = $_FILES['picfile']['name'];
$temp = $_FILES['picfile']['tmp_name'];
$size = $_FILES['picfile']['size'];
$type = $_FILES['picfile']['type'];
echo $name;
echo $temp;
echo $size;
echo $type;
$fp = fopen($temp, 'r');
$content = fread($fp, filesize($temp));
$content = addslashes($content);
fclose($fp);
}
$host="localhost";
$user="myusername";
$pass="mypassword";
mysql_connect($host,$user,$pass);
mysql_select_db($user);
$query= "insert into photo values (NOT NULL, '".$name."','".$type."','".$size."','".$content."')";
$result=mysql_query($query);
if(mysql_affected_rows()==1){
echo '<p>File '.$name.' uploaded</p>';
}else{
echo '<p>Error uplaoding</p>';
}
?>
It says the file has uploaded but in the mysql database the file size is 0 and the 'name' and 'type' column are empty and the content columm says BLOB-0B
thanks for the help in advance.
laura