bberry91
15 Jun 2011, 11:10 PM
i am trying to have a multiple file upload form. here is my form code:
<form action="" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file[]" id="file" /><br />
<input type="file" name="file[]" id="file" /><br />
<input type="file" name="file[]" id="file" />
<br />
<input type="submit" name="uploadFile" value="Upload my Files" />
</form
and then my php:
<?php
$uploadedFile = "uploader.php"; // $_POST['uploadFile']
$path_parts = pathinfo($uploadedFile);
echo $path_parts['extension'];
if (isset($uploadedFile)) {
if ((($path_parts['extension'] == "php") || ($path_parts['extension'] == "txt"))
&& ($_FILES["file"]["size"] < 100000)) // 20000
{
if ($_FILES["file"]["error"] > 0)
{
echo "There was an error uploading your file. <br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
if (file_exists("users/" . $_SESSION['user'] . "/uploads/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"users/" . $_SESSION['user'] . "/uploads/" . $_FILES["file"]["name"]);
echo "This file was successfully uploaded.";
}
}
}
else
{
echo "Invalid file";
}
}
?>
does it have to do with the array? i keep on getting an invalid file error message when trying to upload a .txt file
<form action="" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file[]" id="file" /><br />
<input type="file" name="file[]" id="file" /><br />
<input type="file" name="file[]" id="file" />
<br />
<input type="submit" name="uploadFile" value="Upload my Files" />
</form
and then my php:
<?php
$uploadedFile = "uploader.php"; // $_POST['uploadFile']
$path_parts = pathinfo($uploadedFile);
echo $path_parts['extension'];
if (isset($uploadedFile)) {
if ((($path_parts['extension'] == "php") || ($path_parts['extension'] == "txt"))
&& ($_FILES["file"]["size"] < 100000)) // 20000
{
if ($_FILES["file"]["error"] > 0)
{
echo "There was an error uploading your file. <br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
if (file_exists("users/" . $_SESSION['user'] . "/uploads/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"users/" . $_SESSION['user'] . "/uploads/" . $_FILES["file"]["name"]);
echo "This file was successfully uploaded.";
}
}
}
else
{
echo "Invalid file";
}
}
?>
does it have to do with the array? i keep on getting an invalid file error message when trying to upload a .txt file