Re: Uploading Files
| From: | Rabin Vincent | Date: | Sun, 21 May 2006 10:05:22 +0000 |
| Subject: | Re: Uploading Files | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-236568@lists.php.net to get a copy of this message | ||
On 5/21/06, P. Guethlein <peterg@deltronix.com> wrote:
I'm at one of those frustration levels.... can't seem to get a
script working that will post and upload a file to the server. I"m
working with the below. Can you help?
<?php
$numoffile = 1;
$file_dir = "d:/upload/";
if ($_FILES['myfiles']) {
print_r ($_FILES);
for ($i=0;$i<$numoffile;$i++) {
if (trim($_FILES['myfiles']['name'][$i])!="") {
$newfile = $file_dir.$_FILES['myfiles']['name'][$i];
move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newfile);
$j++;
}
}
}
if (isset($j)&&$j>0) print "Your file(s) has been uploaded.<br>";
echo '
<form enctype="multipart/form-data" action="__URL__" method="POST">
[snipped]
The form's action value should not be __URL__, it should be the
actual URL of the PHP file (eg. http://domain.com/upload.php).
You can also use the following line instead, which will put in the
URL to the current file:
<form enctype="multipart/form-data" action="<?php echo
$_SERVER['PHP_SELF']; ?>" method="POST">
Rabin