Set cookies on file upload in PHP
<p>I have a php upload handler in upload.php, and there, I have to following</p>

<pre><code>&lt;? setcookie("test",100,time()+3600); ?&gt;
</code></pre>

<p>but, when I check the cookies that are set, I dont see any "test" cookie at all.</p>

<p>Can you please help me set a cookie on file upload? why is this upload script any different from any normal script that is accessed by the browser?</p>

<p>Here is the code I have</p>

<pre><code>&lt;?php           
 if (!empty($_FILES)) {            
    if(move_uploaded_file($tempFile,$targetFile))
        {               
                setcookie("targetPath",$targetPath,time() + 3600,'/');
                print $_COOKIE['targetPath']; // prints fine here
                echo 1;
        }
        else
                echo -1;} 
else
{
//print_r($_COOKIE);
print "start cookie &gt;&gt; ";
print $_COOKIE['targetPath']; // does not print when I call upload.php standalone
print " &lt;&lt; end cookie";

}
?&gt;
</code></pre>
