Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old April 24th, 2009, 11:59 AM
Authorized User
Points: 483, Level: 7
Points: 483, Level: 7 Points: 483, Level: 7 Points: 483, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2007
Location: Edgewood, NY, USA.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default capturing file name after upload

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 web.master@male.ru
// 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>
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Clear the filepath details of File Upload Control after saving a file DineshGirij008 C# 2005 0 March 7th, 2009 03:52 AM
Filter File Types in ASP.NET File Upload ramuis78 ASP.NET 2.0 Basics 2 May 31st, 2007 10:50 AM
Capturing\Reading File Contents into DB with PHP aingalsbe PHP How-To 2 December 30th, 2005 09:48 AM
Whole Folder upload(Multi file Upload) ramasamy_rams XML 1 September 9th, 2005 12:43 PM
Capturing date from transferred file Axxess Access VBA 2 July 18th, 2005 05:21 AM



All times are GMT -4. The time now is 01:12 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.