0

I have this php code and I'm trying to get content of image.jpg from url but I need to athuraize my self to the server and I did use the fowling code:

$user = 'username';
$pass = 'password';

$context = stream_context_create(array(
    'http' => array(
        'header'  => "Authorization: Basic " . base64_encode("$user:$pass")
    )
));
$data = file_get_contents("http://mysite/User%20Photos/Profile%20Pictures/bmir_LThumb.jpg", false, $context);

My problem still getting this error:

failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized

I saw many situations like me and I tried their solution like this one but still having problem .

Any help ?

Zizoo
  • 1,694
  • 5
  • 20
  • 42
  • You are unauthorized.you can check your code with new htpasswd. It works. – Hakan SONMEZ Oct 03 '16 at 17:49
  • @HakanSonmez I'm admin now and still having this error , could be the problem with apache configuration ? – Zizoo Oct 04 '16 at 12:59
  • Yes it could be. Please share sample from your htaccess and htpasswd files. – Hakan SONMEZ Oct 04 '16 at 13:26
  • @Hakansonmez I try looking for it at /private/etc/apache2 and I found nothing , can you tell where is it ? – Zizoo Oct 04 '16 at 15:43
  • @hakansonmez btw , the url i'm trying to get its content is for share point and i'm working local in my Mac but connected to the company network – Zizoo Oct 04 '16 at 15:46
  • they are in same folder as your project. If you have one website in your serverr, they are in /var/www/html. Their names are .htaccess and .htpasswd – Hakan SONMEZ Oct 04 '16 at 16:10

0 Answers0