php form upload error

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
hussainhakimuddin
Forum Newbie
Posts: 2
Joined: Mon Sep 12, 2011 9:09 am

php form upload error

Post 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 ?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: php form upload error

Post by AbraCadaver »

You should use move_uploaded_file() instead of copy(), but your problem is that you are using $_FILE instead of $_FILES.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
hussainhakimuddin
Forum Newbie
Posts: 2
Joined: Mon Sep 12, 2011 9:09 am

Re: php form upload error

Post 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 ) )
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: php form upload error

Post by AbraCadaver »

The webserver user doesn't have permission to write to that directory.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply