by jeaddy on Sat Feb 16, 2008 10:48 pm
I have a couple of issue and was hoping if you could help me.
1- I have the codes to upload pix and show them in the browser, but in only does it for one pix at a time and the last one uploaded.
I would like to show all the pixs in the database with the last one uploaded showed last, I tried for the past two days to do this but haven't found any
solution. if you have any let me know.
this is the code on the bottom that does this;
<code>
<?php
// Connect to database
$errmsg = "";
if (! @mysql_connect("localhost","TEST1","TEST")) {
$errmsg = "Cannot connect to database";
}
@mysql_select_db("test");
$q = <<<CREATE
create table pix (
pid int primary key not null auto_increment,
title text,
imgdata longblob)
CREATE;
@mysql_query($q);
// Insert any new image into database
//-------------------------------------------------------------------------------------------
move_uploaded_file($_FILES['imagefile']['tmp_name'],"lates.img");
//MOVE UPLOADED FILE TO A NEW LOCATION
$inst = fopen("lates.img","rb");
$image = addslashes(fread($inst,filesize("lates.img")));
mysql_query ("insert into pix2 (title, imgdata) values (\""."\", \"".$image."\")");
//--------------------------------------------------------------------------------------------------
$gotten = @mysql_query("select imgdata from pix2 order by pid desc");
if ($row = @mysql_fetch_assoc($gotten)) {
$bytes = $row[imgdata];
} else {
$errmsg = "There is no image in the database yet";
$title = "no database image available";
$inst = fopen("../wellimg/ctco.jpg","rb");
$bytes = fread($inst,filesize("../wellimg/ctco.jpg"));
}
if ($_REQUEST[gim] == 1) {
header("Content-type: image/jpeg");
print $bytes;
exit ();
}
?>
<html><head>
<title>Upload an image to a database</title>
<body bgcolor=tan><h2>Here's the latest picture</h2>
<font color=red><?php $errmsg ?></font>
<center><img src=?gim=1 width=1000 height=1000><br> <!--144-->
<b><?php $title ?></center>
<hr>
<h2>Please upload a new picture and title</h2>
<form enctype=multipart/form-data method=post>
<input type=hidden name=MAX_FILE_SIZE value=15000000>
<input type=hidden name=completed value=1>
Please choose an image to upload: <input type=file name=imagefile><br>
Please enter the title of that picture: <input name=whatsit><br>
then: <input type=submit></form><br>
<hr>
</body>
</html>
</code>
2 - do you know if or the codes to upload music and excel files to the database and show them on the browser? I was thinking that maybe I should do it as I
did it for pix and change it to xls for excel docs, etc.
thanks[code][/code]