title: How to pass a file as an argument to php exec?
body: <p>I would like to know how I can pass the content of a file (csv in my case) as an argument for a command line executable (in C or Objective C) to be called by exec in php.</p>
  
  <p>Here is what I have done: the user loads the content of its file from an URL like this:</p>
  
  <pre><code>http://www.myserver.com/model.php?fileName=test.csv
  </code></pre>
  
  <p>Then the following code allows php to parse and load the csv file:</p>
  
  <pre><code>&lt;?php
  
  $f = $_GET['fileName'];
  $handle = fopen("$f", "r"); 
  
  $data = array(); 
  while (($line = fgetcsv($handle)) !== FALSE) { 
  $data[] = $line;
  }
  
  ?&gt;
  </code></pre>
  
  <p>where I'm stuck is how to pass the content of this csv file as an argument to exec. Even if I can assume the csv is known to have only two columns, how many rows it has is user-specific, so I cannot pass all the values one by one as parameters, e.g.</p>
  
  <pre><code>exec("/path_to_executable/model -a $data[0][0] -b $data[0][1] .....");
  </code></pre>
  
  <p>The only alternative solution I guess would be to write something like that:</p>
  
  <pre><code>exec("/path_to_executable/model -fileName test.csv");
  </code></pre>
  
  <p>and have the command line executable do the csv parsing, but in that case, I think I need to have the csv file physically written on the server side. I'm wondering what happens if several people are accessing the webpage at the same time with their own different csv file, are they over-writing each others?</p>
  
  <p>I guess there must be a much proper way to do this and I have not figured it out. Any idea? Thanks!</p>