postgresql - use php variable in php file() -
I have a web site that allows people to upload a CSV file and then load it into the PostGrade database is. The file is ok to upload and I capture the file name and location as I am trying to use this variable in Also to clarify this, Please tolerate me as a relatively new IM in this way. I have also used 2 HTML forms. The top one $ fname variable passes the path from the php code used to upload the file name and file. This is a CSV php copy in the database The following is html to run php. After running different types of variables, to find out where this variable is reaching, I think that because of the next use of this post, if the statement is possibly possible is? ** ** updated ** So a little bit of playing from the walls of my office and after rant ideas almost literally .... I am on the right track Was and Dave was right, my problem was 2 replies to the post's request that a PHP variable I'm sure there are other ways to get it but at the moment it works I'm not sure where you went with printf (), but any print or echo command outputs arguments to the browser and does not return it to the hands on the function. To use a variable as an argument you do not need to use anything special. Just: The printf specifically produces a formatted string and returns the length of the string. So this is equivalent to calling ../data/upload/mycsv.csv as the
$ _ POST ['fname'] .
$ file = file ($ _ POST ['fname']] , but it is having difficulty working , But if I make it hard code as
$ file = file ("../ data / upload / mycsv.csv") this works I have attached the code in question to any help Thanks in advance for
$ _POST resonant ['fname']; Return ../DATA/Uploads/mycsv.csv, which is similar to the hard coded value
& lt; Form method = "post" action = "../... PHP / Loadcsv.php" & gt; & Lt; Input type = "text" value = "& lt ;? php echo htmlspecialchars ($ fname) ;? & gt;" Name = "fname" & gt; & Lt; Br / & gt; & Lt; Input type = "submit" value = "continue" & gt; & Lt; / Form & gt;
& lt; PHP if ($ _POST ['submit']) {$ file = file (printf ($ _ post ['fname'])); // **** does not work ****** // $ file = file ("../ data / upload / csv_trial1.csv"); // ******** This works ****** $ db = pg_connect ("host = localhost dbname = blah user = me password = you"); Pg_exec ($ db, "personal information from copy"); Foreign currency ($ file as $ line) {$ tmp = explosion (",", $ line); Pg_put_line ($ db, sprintf ("% s \ t% s \ t% s \ t% s \ t% s \ t% s \ t% s \ t% s \ n", $ tmp [0], $ tmp [1], $ tmp [2], $ tmp [3], $ tmp [4], $ tmp [5], $ tmp [6], $ tmp [7])); } Pg_put_line ($ db, "\\. \ N"); pg_end_copy ($ Database); ? & Gt;
& lt; Form id = 'form' method = 'post' action = '' & gt; & Lt; Input type = "submit" name = "submit" /> & Lt; / Form & gt;
$ filename = $ _POST ['fname'] in the answer; Take the variable from the first form and input it to another form
& lt; Form id = 'form' method = 'post' action = '' & gt; & Lt; Input type = "hidden" value = "& lt ;? php echo htmlspecialchars ($ filename) ;? & gt;" Name = "fname" & gt; & Lt; Input type = "submit" name = "submit" />
file ($ _ POST ['fname']);
file (integer) , where the value of the integer
$ _ POST ['fname'] is.
Comments
Post a Comment