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 |
Have you checked uploading files from phpmyadmin?
Are you facing same problem there too? Quote:
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. |
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... |
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 |
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 |
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. |
Quote:
Quote:
Quote:
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; Code:
max_allowed_packet=16M |
All times are GMT -5. The time now is 01:18 PM. |