By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,389 Members | 2,010 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,389 IT Pros & Developers. It's quick & easy.

Uploading mutiple binary files in Mysql with Php

P: 41
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 other columns in the row... Could someone help me with this . Below is the complete script...and form..

<?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>";
}
?>
<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>

Thanks in advanced!
Nov 24 '06 #1
Share this Question
Share on Google+
2 Replies


ronverdonk
Expert 2.5K+
P: 4,258
Read the Posting Guidelines about usage of php, code and html tags around code you display! I will not even try to read that code from my screen!

Ronald :cool:
Nov 24 '06 #2

P: 41
Soory for the violation.
Here is the PHP script.
[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 the 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="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 managed to get the the size, name, and type for each the files uploaded to the database but the script only rights the data of the "userfile" value in the form in the database and rewrites to the audio1, audio2..etc..

Ronald thank your for help on my last post,"passing varibles to Php Script" and since then I've managed to find myself in another mess with the above!!!!
Nov 24 '06 #3

Post your reply

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