LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   mysql with php for upload download files to database (https://www.linuxquestions.org/questions/linux-newbie-8/mysql-with-php-for-upload-download-files-to-database-4175462837/)

sandeepc04 05-21-2013 04:01 AM

mysql with php for upload download files to database
 
Hi Friends,

I need some help on mysql database, I have installed RHEL-5.5 and in that mysql is running version 5...


i have created upload and download php scripts, i am able to upload and download files... but here i am not able to upload more than 1mb file size, i have changed values in /etc/php.ini file for post_max_size & post_max_size etc... even its not able to upload large files in that... I have increased value in php scrip also no effect...

here i am putting upload.php script, please let me know if i am doing any where mistakes...


<?php
session_start();
if(!session_is_registered(myusername)){
header("location:index.php");
}
?>
<form name="form1" method="post" action="home.php">
<input type="submit" name="Submit" value="HOME">
</form>
<form name="form1" method="post" action="logout.php">
<input type="submit" name="Submit" value="Logout">
</form>
<html>
<head><title> UPLOAD </title></head>
<?php
//$bg = $_COOKIE['bg'];
//$fg = $_COOKIE['fg'];
$bg="#C0C0C0";
$fg="#100000";
?>

<body bgcolor="<?php echo $bg; ?>" text="<?php echo $fg; ?>">

<center><h1><font color=CCFF33>UPLOAD FILES</font></h1></center>

<body>
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1"
cellspacing="1" class="box">
<tr>
<td>Please Select File</td></tr>
<tr>
<td>
<input type="hidden" name="MAX_FILE_SIZE" value="50000000"\>
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload"
type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['upload'])&&$_FILES['userfile']['size']>0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fileType=(get_magic_quotes_gpc()==0 ? mysql_real_escape_string(
$_FILES['userfile']['type']) : mysql_real_escape_string(
stripslashes ($_FILES['userfile'])));
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
$con = mysql_connect('localhost', 'user', 'password') or die(mysql_error());
$db = mysql_select_db('database', $con);
if($db){
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
mysql_close();
echo "<br>File $fileName Uploaded Successfully<br>";
}else { echo "file upload failed"; }
}
?>
end


Thanks and Regards,
Sandeep CC

fortran 05-21-2013 08:11 AM

Have you checked uploading files from phpmyadmin?
Are you facing same problem there too?
Quote:

Originally Posted by sandeepc04 (Post 4955559)
i have changed values in /etc/php.ini file for post_max_size & post_max_size etc...

Did you mean upload_max_filesize & post_max_size? You must increase value of both parameters.
Did you restart apache after changing in php.ini.
Go to phpmyadmin and click on import, here it shows the max upload size of a file if it is still 1 mb it means you can not upload files more than 1 mb.

If you do not have phpmyadmin, try to upload files using linux terminal. If you can upload from linux terminal or phpmyadmin, it means there is a problem in your php script.

sandeepc04 05-21-2013 08:28 AM

hi,

thanks for your reply,

yes i can upload file from phpmyadmin, its showing that file upload size(Max: 768 kKiB) ...

how can i increase this size?

I have changed upload_max_filesize & post_max_size options in php.ini file then restarted server also, and i can upload and download files from php code which i have posted earlier post... but larger files i am not able to upload...

fortran 05-22-2013 12:06 AM

Here I am talking about the sql file upload in mysql database, I am not talking about image upload or regular file upload through php function.
For configuration, Read this first.
http://www.radinks.com/upload/config.php
Take a look at these threads. These have similar problems with solutions.
http://stackoverflow.com/questions/4...rge-files-fail
http://stackoverflow.com/questions/1...ing-php-apache

sandeepc04 05-22-2013 03:55 AM

hi pavi kanetkar,

Thanks for your reply... no i am not finding any solution by that links...

At least this is possible like, I have data in /home/data/ this files i need to download by browser anywhere... so can i keep this files (.zip, .doc, .exe etc...) in database directly so that i can download by browser? (Like can connect this directory to database?)or would you suggest me any other way to access this data by browser without mysql?


Regards,
Sandeep CC

fortran 05-22-2013 06:54 AM

Suppose webapp is your php-project directory. You can access this on your system using
http://localhost/webapp
If you want to access this in same LAN, you use your LAN IP
http://192.168.1.2/webapp
192.168.2.1 is your system's IP
but you can not access this side outside LAN. you need a static IP ( provided by Internet service provider)
Suppose your static IP is 112.26.54.118
Now you can access your site out side the LAN using
http://112.26.54.118/webapp

Now if you want to download documents through browser.
Put the images, zip file, exe in the directory webapp with sufficient permissions.
Suppose There is a file app.exe in your webapp directory.
Now if you open http://112.26.54.118/webapp/app.exe, it downloads the file outside LAN.

If you want to download inside LAN
http://192.168.1.2/webapp/app.exe is sufficient.

I think 755 to directory webapp (Recursively) is sufficient to download files inside & outside LAN.

TB0ne 05-22-2013 09:39 AM

Quote:

Originally Posted by pavi_kanetkar (Post 4956445)
Suppose webapp is your php-project directory. You can access this on your system using
http://localhost/webapp
If you want to access this in same LAN, you use your LAN IP
http://192.168.1.2/webapp
192.168.2.1 is your system's IP
but you can not access this side outside LAN. you need a static IP ( provided by Internet service provider)
Suppose your static IP is 112.26.54.118
Now you can access your site out side the LAN using
http://112.26.54.118/webapp

Sorry, that's wrong. The IP address assigned by the ISP is for the ISP connection point, which does NOT go back to the internal LAN system. To do that, you need to either do port redirection in your router, or NAT the address somehow. And static IP's are not ALWAYS given by the ISP, only sometimes, depending on your provider/contract. Assuming you just get a static IP is not a good thing, since you may NOT get one, and may not even be ABLE to get one, depending on your provider.
Quote:

Now if you want to download documents through browser.
Put the images, zip file, exe in the directory webapp with sufficient permissions.
Suppose There is a file app.exe in your webapp directory.
Now if you open http://112.26.54.118/webapp/app.exe, it downloads the file outside LAN.

If you want to download inside LAN
http://192.168.1.2/webapp/app.exe is sufficient.
No, sorry, that's wrong, unless a few things happen first. Any files just shoved into that directory will NOT be visible through the web browser, unless you enable the Indexes option in Apache, or install another module to allow http/ftp file browsing. And with default indexing, if you just click a file, it will be executed/ran with whatever helper program is configured, or downloaded (in binary) to your browser if not. Unless you right-click and select "Save link as".
Quote:

I think 755 to directory webapp (Recursively) is sufficient to download files inside & outside LAN.
Yes, and it's also a huge security hole.


OP, if you want to upload files greater than 1 MB, you need to change the max_allowed_packet size. For example, to change it to allow files of up to 16MB, you'd enter:
Code:

SET GLOBAL max_allowed_packet=16*1024*1024;
...at the 'mysql>' prompt. Adjust the formula as needed. You may also need to adjust the max_allowed_packet option in the my.cnf file, such as:
Code:

max_allowed_packet=16M
...and restart MySQL afterwards. Check your mysql log file for errors when you try to upload files greater than 1MB.


All times are GMT -5. The time now is 01:18 PM.