Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Upload Help 1

Status
Not open for further replies.

klaforce

Programmer
Mar 25, 2005
124
US
Hi,
I am working on getting a file upload script working. I am trying to get the example that is used on the PHP.net site. Here is my code:

test.html:
Code:
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="fileUpload.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

Then the fileUpload.php:
Code:
<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

print "<pre>";
if(is_uploaded_file($_FILES['userfile']['tmp_name']))
{
   print "here\n";
   print $_FILES['userfile']['tmp_name']."\n";
   print $_FILES['userfile']['name']."\n";
   
   if(move_uploaded_file($_FILES['userfile']['tmp_name'], $_FILES['userfile']['name']))
       print('here2');
   else
   {
		print_r($_FILES);
		print "Error = ".$_FILES['userfile']['error'];
   }
}
else
{
  // file not uploaded to server
  print('else');
}

print "</pre>";

?>

The print out is as follows:
here
C:\WINDOWS\TEMP\php10.tmp
Todo.txt
Array
(
[userfile] => Array
(
[name] => Todo.txt
[type] => text/plain
[tmp_name] => C:\WINDOWS\TEMP\php10.tmp
[error] => 0
[size] => 814
)

)
Error = 0

Thus, it says the error code is 0 (which according to PHP.net means the upload was successful). However, the file does not exist in the folder I chose, and if it is printing Error = 0, it means that move_file returned false.

Any help here would be appreciated.


Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
you probably dont have write permissions to the destination directory which will be the directory in which you are running the script, if i understand your code correctly.

if you notice the tmp_name element contains the complete path. provide the move_u_l function with a full destination of a directory to which you write permissions and i'll bet that all will work.
 
Hi,
Thanks for the help. I tried changing the permissions of the folder to IIS to write, and gave the move_u_l function a full destination:

Code:
if(move_uploaded_file($_FILES['userfile']['tmp_name'],"C:\\Inetpub\\wwwroot\\notecard\\gwt\\NotesKeith\\src\\com\\public\\".$_FILES['userfile']['name']))
       print('here2');
   else
   {
		print_r($_FILES);
		print "Error = ".$_FILES['userfile']['error'];
   }

This still give the same output. Any other ideas? Thanks again.


Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
it was the IUSR_MACHINENAME to whom you granted write permissions, wasn't it? (assuming IIS)
 
Hey, what happened was I changed the permission from withen IIS manager, but not windows itself. That fixed the problem. Thanks for your help.


Keith


The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top