php - Passing file upload name from $_FILES to $_POST for storage in database -


i'm still new php i'm looking pass name of file that's uploaded can entered database corresponding form information.

// uploading file if ($_files){ print_r($_files); mkdir ($dirname, 0777, true); move_uploaded_file($_files["file"]["tmp_name"],$dirname."/".$_files["file"]["name"]); }   // form processing if($_post['formsubmit'] == "submit") {      $varname = $_post['formname'];     $varlat = $_post['formlat'];     $varlong = $_post['formlong'];     $varpic = $_files["file"]["name"];           $db = mysql_connect($dbhost,$dbuser,$dbpass);         if(!$db) die("error connecting mysql database.");         mysql_select_db($dbname ,$db);          $sql = "insert new_submissions (locationname, latitude, longitude, picture) values (".                         prepsql($varname) . ", " .                         prepsql($varlat) . ", " .                         prepsql($varlong) . ", " .                         prepsql($varpic) . ")";         mysql_query($sql);          header("location: thankyou.html");           exit(); } 

put this

// uploading file if ($_files){ print_r($_files); mkdir ($dirname, 0777, true); move_uploaded_file($_files["file"]["tmp_name"],$dirname."/".$_files["file"]["name"]); } 

inside code

// form processing if($_post['formsubmit'] == "submit") {     if ($_files){       print_r($_files);       mkdir ($dirname, 0777, true);       move_uploaded_file($_files["file"]["tmp_name"],$dirname."/".$_files["file"]["name"]);    }      $varname = $_post['formname'];     $varlat = $_post['formlat'];     $varlong = $_post['formlong'];     $varpic = $_files["file"]["name"];           $db = mysql_connect($dbhost,$dbuser,$dbpass);         if(!$db) die("error connecting mysql database.");         mysql_select_db($dbname ,$db);          $sql = "insert new_submissions (locationname, latitude, longitude, picture) values (".                         prepsql($varname) . ", " .                         prepsql($varlat) . ", " .                         prepsql($varlong) . ", " .                         prepsql($varpic) . ")";         mysql_query($sql);          header("location: thankyou.html");           exit(); } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -