Reputation: 1703
I am trying to get the file path from user and then try to parse it. However, i get error when i run the code.
If i pass the file path manually by putting in my code and then run the program it works fine.
<?php
require_once('SoftLayer/SoapClient.class.php');
$handle4 = fopen ("php://stdin","r");
echo "Enter full file path of the csv file e.g C:\\git\\softlayer-api-php-client\\sample.csv : ";
$path = fgets($handle4);
echo $path;
$f_pointer=fopen(trim($path),"r"); // file pointer
echo 'Done';
?>
Error:
Line 10 $f_pointer=fopen($path,"r");
Upvotes: 0
Views: 1062
Reputation: 97994
Converting the error in your screenshot to text:
Warning: fopen(C:\\git\\softlayer-api-php-client\\sample.csv"
)
That's not word-wrap of the output, because there are longer lines shown, so that must be an actual newline. There's also a stray double-quote there.
In other words, you need to a) validate your input (so that you'd spot the stray "
you entered when testing), and b) run trim()
over it before use, to get rid of the almost inevitable spaces and newlines resulting from its entry.
Upvotes: 1