mulitple image file into mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
beermaker74
Forum Newbie
Posts: 6
Joined: Fri Sep 22, 2006 11:55 am

mulitple image file into mysql

Post by beermaker74 »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello all,
this is my first post. I am a complete newbie at this. I have this problem that I am sure is easy to fix. I need a user to be able to upload 20 images to my mysql database from the web. I have read that this is not a good idea because of server load etc. This is not an issue for me. I need to input about 30 text fields and 20 images in blob. I can input one image and one description with this script

Code: Select all

<?php
if ($action == "upload") {
// ok, let's get the uploaded data and insert it into the db now
include "open_db.inc";

if (isset($binFile) && $binFile != "none") {
$data = addslashes(fread(fopen($binFile, "r"), filesize($binFile)));
$strDescription = addslashes(nl2br($txtDescription));
$sql = "INSERT INTO binary_data ";
$sql .= "(description, bin_data, filename, filesize, filetype) ";
$sql .= "VALUES ('$strDescription', '$data', ";
$sql .= "'$binFile_name', '$binFile_size', '$binFile_type')";
$result = mysql_query($sql, $db);

echo "Thank you. The new file was successfully added to our database.<br><br>";
echo "<a href='main.php'>Continue</a>";
}
mysql_close();

} else {
?>
<HTML><style type="text/css">
<!--
body {
background-color: #FFFFCC;
}
-->
</style><title>Sql image upload form works</title>
<BODY>
<FORM METHOD="post" ACTION="add.php" ENCTYPE="multipart/form-data">
<div align="center">
<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="2000000">
<INPUT TYPE="hidden" NAME="action" VALUE="upload">
Welcome to the image upload page. Just upload away </div>
<TABLE BORDER="1" align="center">
<TR>
<TD>Description: </TD>
<TD><textarea name="txtDescription" rows="5" cols="50"></textarea></TD>
</TR>
<TR>
<TD>File: </TD>
<TD><INPUT TYPE="file" NAME="binFile"></TD>
</TR>
<TR>
<TD COLSPAN="2"><INPUT TYPE="submit" VALUE="Upload"></TD>
</TR>
</TABLE>
</FORM>
</BODY>
</HTML>
<?php
}
?>
can I adjust this script to have the 20 image fields and 20 descriptions that I need. I just can't figure out what I need to change. If there is some other script that I should use then let me know. I am trying my best to learn this. I thank you for your time


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply