Page 1 of 1

php form upload error

Posted: Mon Sep 12, 2011 9:17 am
by hussainhakimuddin
hi, i am trying to code a file uploader in php using IIS server this is the code of the form:

<html><body>

<form method="post" enctype="multipart/form-data" action="processform.php">
<input type="hidden" name="MAX_FILE_SIZE" value="200000">
<input type="file" name="thefile"><br/>
<input type="submit" value="Submit File....">
</form>

</body></html>


this is the code of processform.php

<?php


$upload_dir = "C:/Inetpub/wwwroot/cbt/upload/";
$upload_file = $upload_dir . basename($_FILES['thefile']['name']);

if(copy($_FILE['thefile']['tmp_name'],$upload_file)){
echo "File copy was Successful!";
}
else
{
echo "Oops... something went wrong...";
print_r($_FILES);
}

?>



now the problem is each time i try to click on the submit button after browsing any file it shows the message :
Oops... something went wrong...Array ( [thefile] => Array ( [name] => 1.jpeg [type] => image/jpeg [tmp_name] => C:\temps\php13.tmp [error] => 0 [size] => 59592 ) )
help me guys......
wats the problem with the code ?

Re: php form upload error

Posted: Mon Sep 12, 2011 10:58 am
by AbraCadaver
You should use move_uploaded_file() instead of copy(), but your problem is that you are using $_FILE instead of $_FILES.

Re: php form upload error

Posted: Mon Sep 12, 2011 11:21 am
by hussainhakimuddin
i have done that _FILES editing but now the error is :


Warning: copy(C:/Inetpub/wwwroot/cbt/1.jpeg) [function.copy]: failed to open stream: Permission denied in C:\Inetpub\wwwroot\cbt\processform.php on line 8
Oops... something went wrong...Array ( [thefile] => Array ( [name] => 1.jpeg [type] => image/jpeg [tmp_name] => C:\temps\php84.tmp [error] => 0 [size] => 59592 ) )

Re: php form upload error

Posted: Mon Sep 12, 2011 12:06 pm
by AbraCadaver
The webserver user doesn't have permission to write to that directory.