So what I'm trying to do is this: I've got an integer that's getting passed through a url to my upload.php file which is just a form with a browse button and a submit button like so:
Code: Select all
<html>
<body>
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<input type="hidden" name="number" id="number" value="<?php $cnumber = $_GET['cnumber']; echo $cnumber?>">
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>This next bit of code is the part that actually writes the file to a folder on the server. Again, it's simple enough. I need the integer from the web app to use for the file name because the application is the front end for a database and each file is in reference to the DB.
Code: Select all
<?php
if ($_FILES["file"]["size"] < 2000000)
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["number"]."1".".doc");
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
?>Yes, I realize that forcing the extension on a file without forcing the file type could quite easily create a problem, but I searched high and lo and couldn't find the correct file type syntax for anything besides image files. So if some wonderful soul helps me out and knows how to specify only .doc files can be uploaded, that'd be neat too.
hoping for a solution,
Tom