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 ../data/upload/mycsv.csv as the $ _ POST ['fname'] .

I am trying to use this variable in $ 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

Also to clarify this, $ _POST resonant ['fname']; Return ../DATA/Uploads/mycsv.csv, which is similar to the hard coded value

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. & 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;

This is a CSV php copy in the database

  & 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;   

The following is html to run php. & lt; Form id = 'form' method = 'post' action = '' & gt; & Lt; Input type = "submit" name = "submit" /> & Lt; / Form & gt;

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 $ 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" />   

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: file ($ _ POST ['fname']);

The printf specifically produces a formatted string and returns the length of the string. So this is equivalent to calling file (integer) , where the value of the integer $ _ POST ['fname'] is.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -