move_uploaded_file() can't open stream
<p>I'm trying to upload files via Pycurl through POST, using a PHP script on the receiving end. For some reason the PHP part seems to cause an error. I've distilled it down to two short test scripts.</p>

<pre><code>import pycurl

UPLOADURL = "http://127.0.0.1/~nevon/receive.php" #URL to the PHP script
PATH = "/home/nevon/Desktop/testfile" #path to the file I'm trying to upload

c = pycurl.Curl()
c.setopt(c.POST, 1)
c.setopt(c.URL, UPLOADURL)
c.setopt( c.HTTPPOST, [("uploaded", (c.FORM_FILE, PATH))] )
c.perform()
c.close()
</code></pre>

<p>receive.php:</p>

<pre><code>&lt;?php 
ini_set('display_errors','On');
$target = getcwd()."/upload/"; 
$target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; 

if (move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { 
    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
    } else { 
    echo "Something went wrong."; 
    } 
?&gt;
</code></pre>

<p>The errors I'm receiving when testing this are:</p>

<pre><code>Warning: move_uploaded_file(/home/nevon/public_html/upload/testfile): failed to open stream: No such file or directory in /home/nevon/public_html/receive.php on line 7

Warning: move_uploaded_file(): Unable to move '/tmp/phpevKFCC' to '/home/nevon/public_html/upload/testfile' in /home/nevon/public_html/receive.php on line 7
</code></pre>

<p>It doesn't seem like a permissions problem, but nevertheless I've checked the permissions of both the uploading directory and /tmp. I've also checked so that it isn't a problem with open_basedir restriction.</p>

<p>In the PHP manual on move_uploaded_file() it says the following:</p>

<blockquote>
  <p>move_uploaded_file() ensures the safety of this operation by allowing only those files uploaded through PHP to be moved.</p>
</blockquote>

<p>Since I'm uploading via Python with Curl, I figured that might be the problem. But isn't there supposed to be a different error message if that was the case? <em>If that is indeed the problem, what could I do instead?</em> I haven't really used PHP much for years now, so you could say I'm a little rusty.</p>

<p>I'm not sure if it's relevant, but just in case, I'm testing this on Ubuntu 10.10 with apache 2.2.16, PHP 5.3.3 and Python 2.6.6.</p>

<p>EDIT: The plot thickens! A person on Twitter took my PHP script and put it on his server, to see if he could find out what the problem was. It worked fine for him, when uploading via a regular PHP/HTML form. So I pointed my Python script to his PHP script, and all of a sudden it worked just fine. So now I'm wondering, what's wrong on my end...? How do I troubleshoot this?</p>
