anf.etienne Posted February 5, 2009 Share Posted February 5, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/143952-upload-file/ Share on other sites More sharing options...
anf.etienne Posted February 5, 2009 Author Share Posted February 5, 2009 sorry....here is my form code....can someone tell me where im going wrong? Thank you in advance <!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> and here is my php code <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html><title>Submitting Details.....</title> <? $username="vecre0_tempU"; $password="auction"; $database="vecre0_templates"; $ufile=$_POST['ufile']; $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/>"; 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 $path; } else { echo "Error"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/143952-upload-file/#findComment-755367 Share on other sites More sharing options...
ferozsho Posted February 9, 2009 Share Posted February 9, 2009 Hi! <? $ufile=$_POST['ufile']; $path=$_POST['path']; $file_name = $HTTP_POST_FILES['ufile']['name']; $random_digit=rand(000000,999999); $new_file_name=$random_digit.$file_name; $path= "upload/".$new_file_name; ?> <?php if($ufile !=none){ if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)){ echo "Successful<BR/>"; mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query = "INSERT images VALUES ('','$file_name','$path')"; mysql_query($query); } } mysql_close(); ?> Try it.. Quote Link to comment https://forums.phpfreaks.com/topic/143952-upload-file/#findComment-757958 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.