Upload files WIMP

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
pyoungson
Forum Newbie
Posts: 18
Joined: Thu Aug 09, 2007 5:35 am

Upload files WIMP

Post by pyoungson »

Hi,

I have looked everywhere for an answer to this and implemented lots of different code but none of it works...

I am trying to upload a document to mysql without success. The name, size and file type all upload fine but the content is still a null value. When the file downloads, it is blank for the case of text documents and corrupted in the case of pdfs (although I think that is the way acrobat displays empty files).

Here is the upload form:

Code: Select all

echo "<form action='adviserchange.php?number=$a' method='post' enctype='multipart/form-data'>";
.
.
.
<input type='hidden' name='MAX_FILE_SIZE' value='160000000'>
<input name='userfile' type='file' id='userfile'> 
</td>
<td width='80'></td>
</tr>
</table>
</td></tr>";
  echo "</table>";
 
echo "<input type='hidden' name='id' value='$a' />";
echo "<input type='submit' value='Submit' /></form>";
I have hidden a lot of the form as it is huge, the bit in dots is other inputs which are also passed to the next php page. I really don't think there is a problem with these as the file is clearly being passed to the php as some of its details are appearing in the mysql database. The only thing I can think is that somehow the enctype is wrong?

Here is the upload php:

Code: Select all

$fileName = $_FILES['userfile']['name'];
$tmpName  = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
 
 
 
$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
 
if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}
 
$query = "UPDATE current SET docname='$fileName', docsize='$fileSize', doctype='$fileType', doccontent='$content' WHERE ida = '".$a."'";
 
mysql_query($query) or die('Error, query failed'); 
 
echo "<br /><br />File $fileName uploaded <br />";
And here is the mysql database after this php has run:

[img]
mysql.GIF
mysql.GIF (3.9 KiB) Viewed 212 times
[/img]

I hope that image works here.

I am completely at a loss. I have set all permissions for all users (temporarily), could it be other securities? Perhaps to do with the fact that I'm using IIS and php together.

If someone could pinpoint the problem I'd be massively grateful.

Thanks

P.S. it should definitely be ida and not docid as the mysql field.
Post Reply