likon
03-01-2009, 10:28 AM
hello guys .
i wonder what is the best way that you guys would do for a script that does upload the file and a script that can view uploaded file and click the link and download it .
i am trying to upload the file into database as BLOB type and i am able to do it only for small size files. i can not upload for like 2-5MB (typical an mp3 file )
my code is like this
<?php
require_once("../includes/application.php");
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = (isset($_FILES['userfile']['name'])) ? $_FILES['userfile']['name'] : '';
$tmpName = (isset($_FILES['userfile']['tmp_name'])) ? $_FILES['userfile']['tmp_name'] : '';
$fileSize = (isset($_FILES['userfile']['size'])) ? $_FILES['userfile']['size'] : '';
$fileType = (isset($_FILES['userfile']['type'])) ? $_FILES['userfile']['type'] : '';
$fileError = (isset($_FILES['userfile']['error'])) ? $_FILES['userfile']['error'] : '';
if ($fileError > 0)
echo "errorerrorerror";
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
$connection = new DBManager;
$connection->getConnection();
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
if ($connection->query($query)){
echo "<br/>File $fileName uploaded <br/>";
} else {
echo "$fileName is NOT uploaded";
}
}
?>
<form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<table width="350" border="0" cellpadding="1" cellspacing="1">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="40960">
<input name="userfile" type="file" id="userfile">
</td>
</tr>
</table>
<input name="upload" type="submit" id="upload" value="Upload">
</form>
it wont let me upload file like i guess more that 2MB ( or even more than 1MB )
is there any config in php.ini ( well there is but the max file upload by default is 16M if I am not mistaken ) ....
or Can't I not upload a song file into Database ?
how do you guys normally do for kinda like file manager where one side can upload and one side can download it ?
thanks in advance
i wonder what is the best way that you guys would do for a script that does upload the file and a script that can view uploaded file and click the link and download it .
i am trying to upload the file into database as BLOB type and i am able to do it only for small size files. i can not upload for like 2-5MB (typical an mp3 file )
my code is like this
<?php
require_once("../includes/application.php");
if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = (isset($_FILES['userfile']['name'])) ? $_FILES['userfile']['name'] : '';
$tmpName = (isset($_FILES['userfile']['tmp_name'])) ? $_FILES['userfile']['tmp_name'] : '';
$fileSize = (isset($_FILES['userfile']['size'])) ? $_FILES['userfile']['size'] : '';
$fileType = (isset($_FILES['userfile']['type'])) ? $_FILES['userfile']['type'] : '';
$fileError = (isset($_FILES['userfile']['error'])) ? $_FILES['userfile']['error'] : '';
if ($fileError > 0)
echo "errorerrorerror";
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
$connection = new DBManager;
$connection->getConnection();
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
if ($connection->query($query)){
echo "<br/>File $fileName uploaded <br/>";
} else {
echo "$fileName is NOT uploaded";
}
}
?>
<form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<table width="350" border="0" cellpadding="1" cellspacing="1">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="40960">
<input name="userfile" type="file" id="userfile">
</td>
</tr>
</table>
<input name="upload" type="submit" id="upload" value="Upload">
</form>
it wont let me upload file like i guess more that 2MB ( or even more than 1MB )
is there any config in php.ini ( well there is but the max file upload by default is 16M if I am not mistaken ) ....
or Can't I not upload a song file into Database ?
how do you guys normally do for kinda like file manager where one side can upload and one side can download it ?
thanks in advance