Hello great programmer gurus!
I have this excellent code I want use so my clients can upload photos to their database.
The photos upload successfully. What I need to do is have the file name they uploaded to be entered into the mySQL database.
I have having trouble capturing the file name to be used in the insert query...
Here is my code..... I removed all passwords and names from query for security reasons...
I currently used $buff to try to capture that file name but doesnt work...
<?
// Simple upload interface in PHP.
// Please send your comments to
[email protected]
// 07.11.2001
$UPLOAD_PATH = "/hiddden for security here/"; // directory on the server where are you going to upload files
// on Unix servers directories look like "/home/users/jack/files/"
// Don't forget about final slashes!!!
$UPLOAD_NUM = 1; // the number of upload fields
// display uploaded file list or errors during uploading
// and upload files
function displayUploadedList ()
{
global $UPLOAD_PATH,
$UPLOAD_NUM,
$HTTP_POST_FILES;
$buff = '';
$error = 0;
for ($i = 0; $i < $UPLOAD_NUM; $i++)
{
$name = $HTTP_POST_FILES["File$i"]['name']; // this is the real name of your file
$tmp = $HTTP_POST_FILES["File$i"]['tmp_name']; // this is the temporary name of your file in temporary
// directory on the server
if (!is_uploaded_file ($tmp)) // is this temporary file really uploaded?
continue;
$buff .= "<li><span class=Text><b>".$name."</b></span>";
if (!@move_uploaded_file($tmp, $UPLOAD_PATH."/".$name)) // move temporary file to your upload directory
$error = 1;
}
if (strlen ($buff) == 0)
{
?>
<P align=center class=bodycopy><font color="#FF0000"><b>ALERT! Select at least one file to upload.</b></font></P>
<?
return false;
}
else if ($error)
{
?>
<P align=center class=bodycopy><font color="#FF0000"><b>Some of selected files have not been uploaded.</b></font></P><br>
<P align=center class=bodycopy>Check existence of upload directory: <b><?=$UPLOAD_PATH?></b> and your permissions.</P>
<?
return false;
}
?>
<P align=center class=bodycopy><b>The following file has been uploaded:</b></font></P>
<P class=bodycopy align=center><b><?=$buff?></b></P>
<HR width=400>
<P align=center class=bodycopy>
<b><a href="javascript
:window.close();">Close Window</a></P>
<?
return true;
}
// display upload form
// this is not interesting function ;-(
function displayUploadForm () // display upload form,
{
global $UPLOAD_NUM;
$tablePre = "
<table border=0 cellspacing=0 cellpadding=0 align=center>
<tr>
<td align=left valign=top>
<table border=1 cellspacing=1 cellpadding=6 align=center>
<tr bgcolor=#FFFFFF>
";
$displayed = '';
for ($i = 0; $i < $UPLOAD_NUM; $i++)
{
$displayed .= "<td class=TableElement bgcolor=#CCFFFF><input type=file name=File$i length=25></td></tr>";
}
$tableSuf = "
</table>
</td>
</tr>
</table>
<p align=center><input type=submit name=Upload value=\"Upload Now!\" style=\"font-size: 10pt;\"></p>";
print $tablePre.$displayed.$tableSuf;
}
?>
<?
$name = $_GET["name"];
$con = mysql_connect("blocked out"," "," ");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db(" ", $con);
mysql_query("UPDATE uploadtest SET test = $buff
WHERE item = 'WUC-2442R'");
mysql_close($con);
?>
<html>
<head>
<title>"ODD LIST" Photo Upload System</title>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<BR><BR>
<table border="0" cellspacing="1" cellpadding="5" align="center">
<tr>
<td bgcolor="#FFFFFF" align=center>
<?
print "<span class=subhead><b>Photo Upload</b></span><BR>
<span class=bodycopy>Upload the photo for the item you just entered.<BR><b>Photo MUST be 640 pixels wide x 480 pixels high</b></span>";
?>
</td>
</tr>
<tr>
<form method=POST enctype="multipart/form-data" action="uploadfile.php" >
<td align="left" valign="top" bgcolor="#FFFFFF" height=100%>
<?
displayUploadForm ();
?>
</td>
</tr>
<tr>
<td align="left" valign="top" bgcolor="#FFFFFF" width="50%">
<?
if (isset ($Upload)) // if user has clicked on Upload button we must try to upload something
displayUploadedList ();
?>
</td>
</form>
</tr>
</table>
</body>
</html>