TrevMac Posted March 30, 2007 Share Posted March 30, 2007 Hi, Could someone please help me with the following. I want a client to be able to upload a PDf file into a directory and store its name and path along with some other info in a table in a MySQL database. I want to be able to link to the PDF from a page on the website. My database table consists of the following: Table name - site_sales id - int(10) auto_increment Primary Key title - varchar (200) salespdf - varchar (100) The code I am using is as follows: The problem seems to lie around the $file_name part. If I comment this out and use the form it loads the "title" and the path to the uploads folder (minus the image name and id) into the DB. I am fairly new to this and I am struggling. Even if you could point me in the right direction for a totally new script. ??? if (isset($_POST['submitted'])) { $title = mysql_escape_string(trim($_POST['title'])); $salespdf = mysql_escape_string('http://www.mysite.co.uk/uploads/site_sales_pdf/'); // This bit puts the file in the $file variable into the folder on the server and changes its name so it isn't overwritten $file_name = uniqid("img").".pdf"; if ($file_name !="") { copy ("$file", "/home/mysite/public_html/uploads/site_sales_pdf/$file_name") or die ("Sorry there was a problem");} // This is the SQL part of the code $dbid = mysql_connect ('localhost', 'username, 'password'); mysql_select_db('dbname',$dbid) or die ("Cannot find database"); $query = "INSERT INTO `site_sales` (`title`, `salespdf`) VALUES ('$title', '$salespdf$file_name')"; $result = mysql_query($query,$dbid) or die("INSERT error:".mysql_error()); echo 'Row inserted and image uploaded'; exit; } Would really appreciate some feedback even if it is to tell me to forget what I am doing. Thanx in advance. Link to comment https://forums.phpfreaks.com/topic/44936-need-help-please/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.