![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jan 2005
Location: Albany, NY
Posts: 43
Rep Power: 0
![]() |
Uploading, Making Directory.
Ok, so basically I want it so that whenever someone uploads a file to my server, it makes a directory with a given name, and puts the file in the directory. If that wasn't clear, I'm sure you'll be able to figure what I mean after looking at my script. Anyway, the new directory part is working, but my file won't seem to upload. Script:
HTML PAGE: <form action="/uploadScript.php" enctype="multipart/form-data" method="post"> <input type="text" name="dirName" /> <br /> <input type="hidden" name="MAX_FILE_SIZE" value="51200" /> <input type="file" name="fileUpload" /> <br /> <input type="submit" value="Create Directory" /> </form> PHP PAGE: <? $dirName = $HTTP_POST_VARS['dirName']; $slashName = "\apache2triad\htdocs\\" . $dirName; mkdir($slashName, 0777); print "Name: <font color='red'>".$HTTP_POST_FILES['fileUpload']['name']."</font><br>\n"; print "Size: <font color='red'>".$HTTP_POST_FILES['fileUpload']['size']."</font><br>\n"; if (is_uploaded_file($HTTP_POST_FILES['fileUpload']['tmp_name'])) { move_uploaded_file($HTTP_POST_FILES['fileUpload']['tmp_name'], $slashName); print "<font color='red'><blink>Success!</blink></font>"; } else { print "<font color='red'><blink>Error!</blink></font>"; } ?> I think the problem lays in the move_ uploaded file() function. Any help is apperciated! |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
The problem is most likely to do with the slashName. If you're using Windows, it should be "C:\\Apache2Triad\htdocs\\"; if not, then the slashes are the wrong way round. And please, use [code] and [php] tags.
|
|
|
|
|
|
#3 | |
|
Programmer
Join Date: Jan 2005
Location: Albany, NY
Posts: 43
Rep Power: 0
![]() |
.
Quote:
|
|
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Can I ask where 'tmp_name' came from? I'm no expert on file-handling on PHP, so forgive me if I'm wrong, but I don't see it anywhere else in your code.
|
|
|
|
|
|
#5 |
|
Programmer
Join Date: Jan 2005
Location: Albany, NY
Posts: 43
Rep Power: 0
![]() |
tmp
$HTTP_POST_FILES['fileUpload']['tmp_name'] is a randomized name the your server temporarily gives the file that was uploaded. I'm not sure why it does that, but until you specify a place for the file to go, you need to refer to it by its temporary name.
|
|
|
|
|
|
#6 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
I've been reading up on file uploads, and I've noticed that PHP provides an error code in the event of an error: $_FILES['fileUpload']['error']. Try printing that and finding out if it tells you what's happening. The error code list is at http://www.php.net/manual/en/feature...oad.errors.php.
|
|
|
|
|
|
#7 |
|
Newbie
|
Target File and Dirname
Hello TCStyle,
I have found two important things on your code, that i think it is not correct. First: as far as i know, we cannot use <input type='file'> and <input type='text'> as so easy... i forgot where is the description about it, but when i remark the line $dirName = $HTTP_POST..., then the filesize is in correct size. Second: when we move uploaded file, we have to define the target filename, not just the target directory. Here is work for me: (your code is remarked) <?php
// $dirName = $HTTP_POST_VARS['dirName'];
$dirName = "test";
if ($dirName)
{
// $slashName = "\apache2triad\htdocs\\" . $dirName;
$slashName = "c:\apache\htdocs\\$dirName\\".$_FILES['fileUpload']['name'];
// mkdir($slashName, 0777);
print "Name: <font color='red'>".$_FILES['fileUpload']['name']."</font><br>\n";
print "Size: <font color='red'>".$_FILES['fileUpload']['size']."</font><br>\n";
if (is_uploaded_file($_FILES['fileUpload']['tmp_name'])) {
move_uploaded_file($_FILES['fileUpload']['tmp_name'], $slashName);
print "<font color='red'><blink>Success!</blink></font>";
} else {
print "<font color='red'><blink>Error!</blink></font>";
}
}
?>
__________________
Aryo Sanjaya Sangkan paraning dumadi Manunggaling kawulo gusti |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|