<p>I'm trying to write some PHP to upload a file to a folder on my webserver. Here's what I have:</p>

<pre><code>&lt;?php
    if ( !empty($_FILES['file']['tmp_name']) ) {
        move_uploaded_file($_FILES['file']['tmp_name'], './' . $_FILES['file']['name']);
        header('Location: http://www.mywebsite.com/dump/');
        exit;
    }
?&gt;

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Dump Upload&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;h1&gt;Upload a File&lt;/h1&gt;
        &lt;form action="upload.php" enctype="multipart/form-data" method="post"&gt;
            &lt;input type="hidden" name="MAX_FILE_SIZE" value="1000000000" /&gt;
            Select the File:&lt;br /&gt;&lt;input type="file" name="file" /&gt;&lt;br /&gt;
            &lt;input type="submit" value="Upload" /&gt;
        &lt;/form&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>I'm getting these errors:</p>

<blockquote>
  <p>Warning: move_uploaded_file(./test.txt) [function.move-uploaded-file]: failed to open stream: Permission denied in E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\upload.php on line 3</p>
  
  <p>Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\Temp\phpA30E.tmp' to './test.txt' in E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\upload.php on line 3</p>
  
  <p>Warning: Cannot modify header information - headers already sent by (output started at E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\upload.php:3) in E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\upload.php on line 4</p>
</blockquote>

<p>PHP version 4.4.7
Running IIS on a Windows box. This particular file/folder has 777 permissions.</p>

<p>Any ideas?</p>

[{'answer_id': 3617, 'author': 'sparkes', 'author_id': 269, 'author_profile': 'https://Stackoverflow.com/users/269', 'pm_score': 1, 'selected': False, 'text': "<p>Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\\WINDOWS\\Temp\\phpA30E.tmp' to './people.xml' in E:\\inetpub\\vhosts\\mywebsite.com\\httpdocs\\dump\\upload.php on line 3</p>\n\n<p>is the important line it says you can't put the file where you want it and this normally means a permissions problem</p>\n\n<p>check the process running the app (normally the webservers process for php) has the rights to write a file there.</p>\n\n<p>EDIT:</p>\n\n<p>hang on a bit\nI jumped the gun a little is the path to the file in the first line correct?</p>\n"}, {'answer_id': 3618, 'author': 'Michael Stum', 'author_id': 91, 'author_profile': 'https://Stackoverflow.com/users/91', 'pm_score': 4, 'selected': True, 'text': '<p>As it\'s Windows, there is no real 777. If you\'re using <a href="http://fr2.php.net/manual/en/function.chmod.php" rel="noreferrer">chmod</a>, check the Windows-related comments.</p>\n\n<p>Check that the IIS Account can access (read, write, modify) these two folders:</p>\n\n<pre><code>E:\\inetpub\\vhosts\\mywebsite.com\\httpdocs\\dump\\\nC:\\WINDOWS\\Temp\\\n</code></pre>\n'}, {'answer_id': 4618, 'author': 'Kevin', 'author_id': 40, 'author_profile': 'https://Stackoverflow.com/users/40', 'pm_score': 2, 'selected': False, 'text': "<p>Try adding a path.  The following code works for me:</p>\n\n<pre><code>&lt;?php\n\nif ( !empty($_FILES['file']) ) {\n    $from = $_FILES['file']['tmp_name'];\n    $to = dirname(__FILE__).'/'.$_FILES['file']['name'];\n\n    if( move_uploaded_file($from, $to) ){\n        echo 'Success';   \n    } else {\n        echo 'Failure';   \n    }\n\n    header('Location: http://www.mywebsite.com/dump/');\n    exit;\n}\n?&gt;\n</code></pre>\n"}, {'answer_id': 365455, 'author': 'jmucchiello', 'author_id': 44065, 'author_profile': 'https://Stackoverflow.com/users/44065', 'pm_score': 4, 'selected': False, 'text': "<p>OMG</p>\n\n<pre><code>move_uploaded_file($_FILES['file']['tmp_name'], './' . $_FILES['file']['name']);\n</code></pre>\n\n<p>Don't do that. <code>$_FILES['file']['name']</code> could be <code>../../../../boot.ini</code> or any number of bad things. You should never trust this name. You should rename the file something else and associate the original name with your random name. At a minimum use <code>basename($_FILES['file']['name'])</code>.</p>\n"}, {'answer_id': 542368, 'author': 'rupert0', 'author_id': 42060, 'author_profile': 'https://Stackoverflow.com/users/42060', 'pm_score': 1, 'selected': False, 'text': '<p>Another think to observe  is your directory separator, you are using / in a Windows box..</p>\n'}, {'answer_id': 1837584, 'author': 'sameer', 'author_id': 223516, 'author_profile': 'https://Stackoverflow.com/users/223516', 'pm_score': 1, 'selected': False, 'text': "<p>Add the IIS user in the 'dump' folders security persmissions group, and give it read/write access.</p>\n"}, {'answer_id': 13416957, 'author': 'Soumya Roy', 'author_id': 1829575, 'author_profile': 'https://Stackoverflow.com/users/1829575', 'pm_score': 0, 'selected': False, 'text': '<p>Create a folder named "image" with folder permission <code>777</code></p>\n\n<pre><code>&lt;?php\n    move_uploaded_file($_FILES[\'file\'][\'tmp_name\'],"image/".$_FILES[\'file\'][\'name\']);\n?&gt;\n</code></pre>\n'}, {'answer_id': 59200854, 'author': 'Rod Fuller', 'author_id': 12487347, 'author_profile': 'https://Stackoverflow.com/users/12487347', 'pm_score': 0, 'selected': False, 'text': "<p>We found using below path</p>\n\n<p><code>{['DOCUMENT_ROOT'] + 'path to folder'</code> </p>\n\n<p>and giving everyone full access to the folder resolved the issue. </p>\n\n<p>Make sure to not reveal the location in the address bar. No sense in giving the location away.</p>\n"}]
['https://Stackoverflow.com/questions/3611', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/402/']