upload file
Posted: Thu Feb 05, 2009 11:55 am
hi i have gone on php.net to learn how to upload files.....i have done this and it works. But my main aim is to save the location of the file to a db so i can recall it later but right now it is only inputting the words ufile and path instead of the file path....here is a link to the test file im using and you can see that i can echo the full path but i cant post it to the db
http://ve-creative.com/test/2/index3.html
Can someone tell me where i am going wrong?
here is my html
and here is my php
http://ve-creative.com/test/2/index3.html
Can someone tell me where i am going wrong?
here is my html
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="upload_rename_ac.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>Single File Upload </strong></td>
</tr>
<tr>
<td>Select file
<input name="ufile" type="file" id="ufile" size="50" /></td><br />
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<body>
</body>
</html>
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><title>Submitting Details.....</title>
<?php
$username="vecre0_tempU";
$password="auction";
$database="vecre0_templates";
$ufile=$_POST['ufile'];
$full_path=$_POST['path'];
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT images VALUES ('','ufile','path')";
mysql_query($query);
mysql_close();
?>
<?php
$file_name = $HTTP_POST_FILES['ufile']['name'];
$random_digit=rand(000000,999999);
$new_file_name=$random_digit.$file_name;
$path= "upload/".$new_file_name;
if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>";
$full_path="http://ve-creative.com/test/2/".$path;
echo "File Name :".$new_file_name."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>";
echo $full_path;
}
else
{
echo "Error";
}
}
?>