Search code examples
phpfile-get-contentsinvalid-argument

file_get_contents() error: failed to open stream : invalid argument


$i = 0;   

$name_url = '../../accounts/full/'.$frd_array[$i].'/profile/name.txt';
$name = file_get_contents($name_url);
$user_id = file_get_contents('../../accounts/full/'.$frd_array[$i].'/profile/user_id.txt');
$status = file_get_contents('../../accounts/full/'.$frd_array[$i].'/profile/status.txt');

echo "
        <div class='frd_acc'>
        <img class='c_avatar' src='../accounts/full/".$frd_array[$i]."/profile/avatar.png'>
        <div class='c_name'>".$name."</div> <kbd class='c_user_id'>".$user_id."</kbd>
        <div class='status'>".$status."</div>
        </div>"

above is my php code. when im executing this php script im getting the following errors:

Warning: file_get_contents(../../accounts/full/amaan2 amaan2 /profile/name.txt): failed to open stream: Invalid argument in E:\FreeJi\php\chats\my_frds.php on line 16

Warning: file_get_contents(../../accounts/full/amaan2 amaan2 /profile/user_id.txt): failed to open stream: Invalid argument in E:\FreeJi\php\chats\my_frds.php on line 17

Warning: file_get_contents(../../accounts/full/amaan2 amaan2 /profile/status.txt): failed to open stream: Invalid argument in E:\FreeJi\php\chats\my_frds.php on line 18

Please Help ME!!!


Solution

  • Please do

    $name_url = '../../accounts/full/'.trim($frd_array[$i]).'/profile/name.t‌​xt';
    

    in order to remove extra spaces