bruckerrlb Posted January 27, 2008 Share Posted January 27, 2008 Hello all, I have been wracking my brains with this for a while now, I am uploading a file, the file uploads, then it writes to a database, that is all good, but one of my fields in the database is the path. I am trying to get the name of the file inserted into the database, and now it's not going in, nothing is going in the path field, only the primary id, and another field I have set up. <?php error_reporting(1); $filepath = getcwd()."/files/"; //This is what I thought was correct, how to get the name of the file, but it's not showing up in my //database. $uploadfile = $filepath . basename($_FILES['userfile']['name']); if(!file_exists($filepath)) { mkdir($filepath,0777); } chmod($filepath,0777); if(move_uploaded_file($_FILES['Filedata']['tmp_name'], $filepath.$_FILES['Filedata']['name'])){ chmod($filepath.$_FILES['Filedata']['name'], 0777); $link = mysql_connect("localhost","a username","a password"); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db("thedb"); if(!$db) { die("Unable to select db"); } $query = "INSERT INTO video (id, path, page) VALUES (0, '$uploadfile', 'livevideo')"; if (@mysql_query ($query)) { print 'Successfully Added!'; } mysql_close(); } ?> So the following code returns me the entire path minus the name of the file, just the path to the folder that the file is in, and when I use the following as my variable, it returns nothing $uploadfile = $_FILES['userfile']['name']; I was reading the php site, and the first way is how they have there code set up, but it doesn't seem to be working for me, or they are trying to do something different, does anyone have any tips? Quote Link to comment https://forums.phpfreaks.com/topic/88044-solved-php-upload-script-not-writing-to-database-correctly/ Share on other sites More sharing options...
bruckerrlb Posted January 27, 2008 Author Share Posted January 27, 2008 FYI I figured this out, see code below for explanation $uploadfile = $_FILES['Filedata']['name']; where filedata is, it has to be the name on the form uploader, I was using userfile, which is the <i>example</i> on the php site! Quote Link to comment https://forums.phpfreaks.com/topic/88044-solved-php-upload-script-not-writing-to-database-correctly/#findComment-450452 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.