0

I have an admin panel which is coded with ASP.net (C#). I have a textarea like wordpress (redactor) and i am trying to upload image with it. I am using PHP file to make upload but after everytime I upload an image, I encounter with IIS "401 - Unauthorized: Access is denied due to invalid credentials." error while displaying it. I would like to add 755 Permission to IIS_IUSR every timem after file upload. Is it possible?

Here is my php code:

    $dir = 'assets/images/content/';

    $_FILES['file']['type'] = strtolower($_FILES['file']['type']);

    if ($_FILES['file']['type'] == 'image/png'
    || $_FILES['file']['type'] == 'image/jpg'
    || $_FILES['file']['type'] == 'image/gif'
    || $_FILES['file']['type'] == 'image/jpeg'
    || $_FILES['file']['type'] == 'image/pjpeg')
    {



        // setting file's mysterious name
        $filename = md5(date('YmdHis')).'.jpg';
        $file = $dir.$filename;

        // copying
        move_uploaded_file($_FILES['file']['tmp_name'], $file);

        chmod($file, 0777);

        // displaying file
        $array = array(
            'filelink' => 'assets/images/content/'.$filename
        );

        echo stripslashes(json_encode($array));

    }
ganchito55
  • 3,559
  • 4
  • 25
  • 46
Berk Kaya
  • 450
  • 2
  • 9
  • 18
  • You are using IIS or apache? – chris85 Apr 19 '16 at 20:15
  • 1
    `stripslashes(json_encode())` is horribly bad. json can/will add **NECESSARY** escaping backslashes to the data being encoded, which stripslashes will then happily remove, corrupting the json. – Marc B Apr 19 '16 at 20:20
  • Hmm haven't worked with IIS 8 but IIS 7 didn't use those file modes. http://stackoverflow.com/questions/5887131/add-writing-permission-to-php-on-iis-7 – chris85 Apr 19 '16 at 20:21
  • @chris85 already checked that topic but doesnt work on IIS 8 – Berk Kaya Apr 19 '16 at 20:29

2 Answers2

0

try this: Computer Management (right click on my computer and select Manage) --> Local Users and Groups --> Users --> Select IUSR_MACHINENAME (ie,IUSR_TOMATO-CLOWNFIS) --> Right click Properties --> Make sure it is a member of IIS_WPG and users and not Guests.

Voigt
  • 69
  • 1
  • 2
  • There are no users which start with IUSR. ADMINISTRATOR,IME_ADMIN, IME_USER, ENTRENIX, MYadmin, Statsx are the users. – Berk Kaya Apr 19 '16 at 20:26
0

I have changed my TEMP folder permissions and its fixed. I hope it will help someone else.

Berk Kaya
  • 450
  • 2
  • 9
  • 18