LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-21-2013, 05:01 AM   #1
sandeepc04
Member
 
Registered: Jun 2012
Location: India
Posts: 66

Rep: Reputation: Disabled
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
 
Old 05-21-2013, 09:11 AM   #2
fortran
Member
 
Registered: Nov 2011
Location: Cairo, Egypt
Distribution: CentOS, RHEL, Fedora
Posts: 300
Blog Entries: 2

Rep: Reputation: 51
Have you checked uploading files from phpmyadmin?
Are you facing same problem there too?
Quote:
Originally Posted by sandeepc04 View Post
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.
 
Old 05-21-2013, 09:28 AM   #3
sandeepc04
Member
 
Registered: Jun 2012
Location: India
Posts: 66

Original Poster
Rep: Reputation: Disabled
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...
 
Old 05-22-2013, 01:06 AM   #4
fortran
Member
 
Registered: Nov 2011
Location: Cairo, Egypt
Distribution: CentOS, RHEL, Fedora
Posts: 300
Blog Entries: 2

Rep: Reputation: 51
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
 
Old 05-22-2013, 04:55 AM   #5
sandeepc04
Member
 
Registered: Jun 2012
Location: India
Posts: 66

Original Poster
Rep: Reputation: Disabled
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
 
Old 05-22-2013, 07:54 AM   #6
fortran
Member
 
Registered: Nov 2011
Location: Cairo, Egypt
Distribution: CentOS, RHEL, Fedora
Posts: 300
Blog Entries: 2

Rep: Reputation: 51
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.
 
Old 05-22-2013, 10:39 AM   #7
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,932

Rep: Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692Reputation: 3692
Quote:
Originally Posted by pavi_kanetkar View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] yum install php-mysql create problem to my running mysql database jsaravana87 Linux - Server 1 08-11-2011 04:24 AM
PHP how to upload and download files darkangel29 Programming 1 06-01-2011 07:39 PM
PHP upload/download speed tester ? NaCo Linux - Server 2 12-29-2009 10:51 PM
upload of image in database (php+mysql) Pravab Programming 5 11-08-2006 12:05 PM
Upload MySQL database Swift&Smart Linux - Software 4 05-19-2003 04:30 AM


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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration