Please help me on this file upload.

<form id="form_2" action="files_upload.php" method="post" enctype="multipart/form-data">
        	
     <input type="hidden" name="MAX_FILE_SIZE" value="50000000">
     File:<input type="file"  name="file" class="input" maxlength="350"" /><br />
     <input type="submit" name="submit" value="Upload File">
</form>
<?php
if(isset($_POST['submit']) && $_FILES['file']['size'] > 0)
{
$fileName = $_FILES['file']['name'];
$tmpName  = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileType = $_FILES['file']['type'];

$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);


if(!get_magic_quotes_gpc())
{
    $fileName = addslashes($fileName);
}

mysql_connect('localhost', 'username', '*********') or die(mysql_error());
mysql_select_db('db') or die(mysql_error());


$query = "INSERT INTO `db`.`upload` (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

mysql_query($query) or die('Error, query failed');
//include 'library/closedb.php';

echo "<br>File $fileName uploaded<br>";
echo "<br><a href=\"index.php\">[Back]</a><br>";
}
?>

Recommended Answers

All 2 Replies

php.ini is to be modified for limit of file size. html parameter will not help

open php.ini (must be at your MAIN PHP directory)
edit those two lines:

post_max_size = 2M
upload_max_filesize = 2M

Enter what ever you want for value.

P.S. Don't forget, after change those settings you need to restart your webserver(apache or what ever you use)!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.