473,394 Members | 1,971 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Uploading mutiple binary files to single row in Mysql with Php

I need a little help figuring this one out. I have a script that I've modified to post mutiple binary files into a single row but instead of copying the indiviuals files it rewrites the first file to all the other columns in the row... Could someone help me with this . Below is the complete script...and form..

[PHP]
<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size'] && $_FILES['audiofile1']['size'] && $_FILES['audiofile2']['size'] && $_FILES['audiofile3']['size'] && $_FILES['audiofile4']['size'] && $_FILES['audiofile5']['size'] && $_FILES['audiofile6']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
$fileName1 = $_FILES['audiofile1']['name'];
$tmpName1 = $_FILES['audiofile1']['tmp_name'];
$fileSize1 = $_FILES['audiofile1']['size'];
$fileType1 = $_FILES['audiofile1']['type'];

$fp = fopen($tmpName, 'r');
$audiofile1 = fread($fp, filesize($tmpName));
$audiofile1 = addslashes($audiofile1);
fclose($fp);
$fileName2 = $_FILES['audiofile2']['name'];
$tmpName2 = $_FILES['audiofile2']['tmp_name'];
$fileSize2 = $_FILES['audiofile2']['size'];
$fileType2 = $_FILES['audiofile2']['type'];

$fp = fopen($tmpName, 'r');
$audiofile2 = fread($fp, filesize($tmpName));
$audiofile2 = addslashes($audiofile2);
fclose($fp);
$fileName3 = $_FILES['audiofile3']['name'];
$tmpName3 = $_FILES['audiofile3']['tmp_name'];
$fileSize3 = $_FILES['audiofile3']['size'];
$fileType3 = $_FILES['audiofile3']['type'];

$fp = fopen($tmpName, 'r');
$audiofile3 = fread($fp, filesize($tmpName));
$audiofile3 = addslashes($audiofile3);
fclose($fp);
$fileName4 = $_FILES['audiofile4']['name'];
$tmpName4 = $_FILES['audiofile4']['tmp_name'];
$fileSize4 = $_FILES['audiofile4']['size'];
$fileType4 = $_FILES['audiofile4']['type'];

$fp = fopen($tmpName, 'r');
$audiofile4 = fread($fp, filesize($tmpName));
$audiofile4 = addslashes($audiofile4);
fclose($fp);
$fileName5 = $_FILES['audiofile5']['name'];
$tmpName5 = $_FILES['audiofile5']['tmp_name'];
$fileSize5 = $_FILES['audiofile5']['size'];
$fileType5 = $_FILES['audiofile5']['type'];

$fp = fopen($tmpName, 'r');
$audiofile5 = fread($fp, filesize($tmpName));
$audiofile5 = addslashes($audiofile5);
fclose($fp);
$fileName6 = $_FILES['audiofile6']['name'];
$tmpName6 = $_FILES['audiofile6']['tmp_name'];
$fileSize6 = $_FILES['audiofile6']['size'];
$fileType6 = $_FILES['audiofile6']['type'];

$fp = fopen($tmpName, 'r');
$audiofile6 = fread($fp, filesize($tmpName));
$audiofile6 = addslashes($audiofile6);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$fileName1 = addslashes($fileName1);
$fileName2 = addslashes($fileName2);
$fileName3 = addslashes($fileName3);
$fileName4 = addslashes($fileName4);
$fileName5 = addslashes($fileName5);
$fileName6 = addslashes($fileName6);
}
include 'config.php';
include 'opendb.php';

$query = "INSERT INTO audio (name, size, type, content, name1, size1, type1, audiofile1, name2, size2, type2, audiofile2, name3, size3, type3, audiofile3, name4, size4, type4, audiofile4, name5, size5, type5, audiofile5, name6, size6, type6, audiofile6 ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$fileName1', '$fileSize1', '$fileType1', '$audiofile1', '$fileName2', '$fileSize2', '$fileType2', '$audiofile2', '$fileName3', '$fileSize3', '$fileType3', '$audiofile3', '$fileName4', '$fileSize4', '$fileType4', '$audiofile4', '$fileName5', '$fileSize5', '$fileType5', '$audiofile5', '$fileName6', '$fileSize6', '$fileType6', '$audiofile6')";

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

echo "<br>File $fileName uploaded<br> File $fileName1 uploaded<br>File $fileName2 uploaded<br>File $fileName3 uploaded<br>File $fileName4 uploaded<br>File $fileName5 uploaded<br>File $fileName6 uploaded<br>";
}
?>
[/PHP]
and heres the HTML Form
[HTML]
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="8888000000">
<input name="userfile" type="file" id="userfile">
</td>
</tr>
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="888000000">
<input name="audiofile1" type="file" id="audiofile1">
</td>
</tr>
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="888000000">
<input name="audiofile2" type="file" id="audiofile2">
</td>
</tr>
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="8888000000">
<input name="audiofile3" type="file" id="audiofile3">
</td>
</tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="8888000000">
<input name="audiofile4" type="file" id="audiofile4">
</td>
</tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="888000000">
<input name="audiofile5" type="file" id="audiofile5">
</td>
</tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="8888000000">
<input name="audiofile6" type="file" id="audiofile6">
</td>
</tr>
<tr>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
[/HTML]

I've been playing with this for about a week and for some reason I can't get it to work..Any help would be greatly appreciated!
Nov 27 '06 #1
10 1928
ronverdonk
4,258 Expert 4TB
Why are you using the same statement for every to be uploaded file?
Expand|Select|Wrap|Line Numbers
  1. $fp = fopen($tmpName, 'r');
  2.  
Ronald :cool:
Nov 27 '06 #2
I assumed the statement was required for each of the files that are being uploaded to the db.
Nov 27 '06 #3
Ronald," after reading your post I made a modification to the script and manage to figure out how to get mutiple files uploaded using this shorten version of the orginal post
However another issue arose!
[PHP]
<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size']&& $_FILES['audiofile1']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

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

$fileName1 = $_FILES['audiofile1']['name1'];
$tmpName1 = $_FILES['audiofile1']['tmp_name'];
$fileSize1 = $_FILES['audiofile1']['size1'];
$fileType1 = $_FILES['audiofile1']['type1'];

$fp = fopen($tmpName1, 'r');
$audiofile1 = fread($fp, filesize($tmpName));
$audiofile1 = addslashes($audiofile1);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$fileName1 = addslashes($fileName1);
}
include 'config.php';
include 'opendb.php';

$query = "INSERT INTO audio (name, size, type, content, name1, size1, type1, audiofile1 ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$fileName1', '$fileSize1', '$fileType1', '$audiofile1')";

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

echo "<br>File $fileName uploaded<br>File $fileName1 uploaded<br>";
}
?>
[/PHP]

And the html form looks like this
[HTML]
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="8000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="8000000">
<input name="audiofile1" type="file" id="audiofile1">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
[/HTML]

the only problem is that none of the atribute information is being store in the database for the audio file1. The file name1, size1, type1 are blank just the binary data is being stored.

Thanks again for your help..
Nov 28 '06 #4
And as far as RTFM being almost extinct. I think most just don't have time with fast pace of life and all but here something for your amusement! Here my first website no training, no mentor's, nothing but a desire to learn..I know this doesn't come close what others can do but I'll get there one day..
[HTML]
http://www.atlantasundergroundhits.com/
[/HTML]

best veiwed in internet explorer..

Thanks again for you help..
RTFM "lol"
Nov 28 '06 #5
ronverdonk
4,258 Expert 4TB
Great site!
However, you still have an erroneous statements [php]$audiofile1 = fread($fp, filesize($tmpName));
$tmpName1 = $_FILES['audiofile1']['tmp_name'];[/php]

Ronald :cool:
Nov 28 '06 #6
I'll check into this today when I get home.

Thanks Ronald.
Nov 28 '06 #7
It took me about 4 hours but I figured it out here's the PHP I took into account your recommendations..

[PHP]
<?php
if(isset($_POST['upload']) && $_FILES['userfile']['size'] && $_FILES['audiofile1']['size'] && $_FILES['audiofile2']['size'] && $_FILES['audiofile3']['size'] && $_FILES['audiofile4']['size'] && $_FILES['audiofile5']['size'] && $_FILES['audiofile6']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$fileName1 = $_FILES['audiofile1']['name'];
$tmpName1 = $_FILES['audiofile1']['tmp_name'];
$fileSize1 = $_FILES['audiofile1']['size'];
$fileType1 = $_FILES['audiofile1']['type'];

$fileName2 = $_FILES['audiofile2']['name'];
$tmpName2 = $_FILES['audiofile2']['tmp_name'];
$fileSize2 = $_FILES['audiofile2']['size'];
$fileType2 = $_FILES['audiofile2']['type'];

$fileName3 = $_FILES['audiofile3']['name'];
$tmpName3 = $_FILES['audiofile3']['tmp_name'];
$fileSize3 = $_FILES['audiofile3']['size'];
$fileType3 = $_FILES['audiofile3']['type'];

$fileName4 = $_FILES['audiofile4']['name'];
$tmpName4 = $_FILES['audiofile4']['tmp_name'];
$fileSize4 = $_FILES['audiofile4']['size'];
$fileType4 = $_FILES['audiofile4']['type'];

$fileName5 = $_FILES['audiofile5']['name'];
$tmpName5 = $_FILES['audiofile5']['tmp_name'];
$fileSize5 = $_FILES['audiofile5']['size'];
$fileType5 = $_FILES['audiofile5']['type'];

$fileName6 = $_FILES['audiofile6']['name'];
$tmpName6 = $_FILES['audiofile6']['tmp_name'];
$fileSize6 = $_FILES['audiofile6']['size'];
$fileType6 = $_FILES['audiofile6']['type'];

$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
$fp = fopen($tmpName1, 'r');
$audiofile1 = fread($fp, filesize($tmpName1));
$audiofile1 = addslashes($audiofile1);
$fp = fopen($tmpName2, 'r');
$audiofile2 = fread($fp, filesize($tmpName2));
$audiofile2 = addslashes($audiofile2);
$fp = fopen($tmpName3, 'r');
$audiofile3 = fread($fp, filesize($tmpName3));
$audiofile3 = addslashes($audiofile3);
$fp = fopen($tmpName4, 'r');
$audiofile4 = fread($fp, filesize($tmpName4));
$audiofile4 = addslashes($audiofile4);
$fp = fopen($tmpName5, 'r');
$audiofile5 = fread($fp, filesize($tmpName5));
$audiofile5 = addslashes($audiofile5);
$fp = fopen($tmpName6, 'r');
$audiofile6 = fread($fp, filesize($tmpName6));
$audiofile6 = addslashes($audiofile6);

fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$fileName1 = addslashes($fileName1);
$fileName2 = addslashes($fileName2);
$fileName3 = addslashes($fileName3);
$fileName4 = addslashes($fileName4);
$fileName5 = addslashes($fileName5);
$fileName6 = addslashes($fileName6);

}
include 'config.php';
include 'opendb.php';

$query = "INSERT INTO audio (name, size, type, content, name1, size1, type1, audiofile1, name2, size2, type2, audiofile2, name3, size3, type3, audiofile3, name4, size4, type4, audiofile4, name5, size5, type5, audiofile5, name6, size6, type6, audiofile6 ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$fileName1', '$fileSize1', '$fileType1', '$audiofile1', '$fileName2', '$fileSize2', '$fileType2', '$audiofile2', '$fileName3', '$fileSize3', '$fileType3', '$audiofile3', '$fileName4', '$fileSize4', '$fileType4', '$audiofile4', '$fileName5', '$fileSize5', '$fileType5', '$audiofile5', '$fileName6', '$fileSize6', '$fileType6', '$audiofile6')";

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

echo "<br>File $fileName uploaded<br> File $fileName1 uploaded<br>File $fileName2 uploaded<br>File $fileName3 uploaded<br>File $fileName4 uploaded<br>File $fileName5 uploaded<br>File $fileName6 uploaded<br>File $fileName7 uploaded<br>";
}
?>
[/PHP]

the form

[HTML]
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="8888000000">
<input name="userfile" type="file" id="userfile">
</td>
</tr>
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="888000000">
<input name="audiofile1" type="file" id="audiofile1">
</td>
</tr>
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="888000000">
<input name="audiofile2" type="file" id="audiofile2">
</td>
</tr>
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="8888000000">
<input name="audiofile3" type="file" id="audiofile3">
</td>
</tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="8888000000">
<input name="audiofile4" type="file" id="audiofile4">
</td>
</tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="888000000">
<input name="audiofile5" type="file" id="audiofile5">
</td>
</tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="8888000000">
<input name="audiofile6" type="file" id="audiofile6">
</td>
</tr>
<tr>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
[/HTML]

The script uploads mutiple file with all the atribute information...
But I came across another issue when attempting upload a audio file and large images the blob feilds only allow 64 kilobytes to written to db. I think I
read acorss some documentation that said mysql by default only allows for 1 mega byte to be uploaded.. any idea's

Thanks for your help Ronald
great examples
Nov 29 '06 #8
ronverdonk
4,258 Expert 4TB
The following are the maximum sizes for each BLOB field:

- TINYBLOB = 255 bytes
- BLOB = 65535 bytes
- MEDIUMBLOB = 16777215 bytes
- LONGBLOB = 4294967295 bytes

Robald :cool:
Nov 29 '06 #9
I think you have copied the code for each files
for eg: $tmpName is used for first file and for other files you have used the same
$tmpName
I mean There should be $tmpName1 in place of bold parts and similartly to to tmpName2,3,4,5,6:

$fileName1 = $_FILES['audiofile1']['name'];
$tmpName1 = $_FILES['audiofile1']['tmp_name'];
$fileSize1 = $_FILES['audiofile1']['size'];
$fileType1 = $_FILES['audiofile1']['type'];

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

Hope it is the right error
Nov 30 '06 #10
Ronald that did the trick I was able to successfully upload audio files....

Now on to the next task....

Thanks again
Nov 30 '06 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Ron Brennan | last post by:
Good afternoon. The entire task that I'm trying to achieve is to allow a user to browse and upload multiple files simultaneously, hiding the Browse button of <input> tags of type="file" and...
5
by: Kevin Ollivier | last post by:
Hi all, I've come across a problem that has me stumped, and I thought I'd send a message to the gurus to see if this makes sense to anyone else. =) Basically, I'm trying to upload a series of...
0
by: Jean Hagen | last post by:
I'm trying to write a script to weekly remove MySQL logs, the general, error and binary log files. Following the MySQL documentation, I've written a script that moves all current log files, then...
10
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
5
by: Chris | last post by:
I have a meetings section I'm developing on our intranet. Using PHP/MySQL. Meeting info and Meeting docs reside on 2 related tables in the db. Users may want to upload anywhere from 1 to 10 or...
2
by: underground | last post by:
I need a little help figuring this one out. I have a script that should post mutiple binary files into a single row but instead of copying the indiviuals files it rewrites the first file to all the...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
2
by: matech | last post by:
I have a problem with uploading special characters from excel files to mysql 5. It doesn't matter if I use UTF-8 or iso-8859-1 when uploading the trademark ™ symbol. htmlspecialchars() or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.