I am trying to upload 2 files, the first one is a flash (.swf) file and the second a .png.
At the moment, I would have no problem making 2 different php upload file, with 2 different forms, but Im sure there can be a way to make that all together.
I am not really experimented with PHP, but Im trying to learn.
At the moment I have this:
<?ph开发者_如何学编程p
$allowed_filetypes = array('.swf','.png');
$max_filesize = 10524288;
$upload_path = 'swf/';
$filename = $_FILES['userfile']['name'];
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
if(move_uploaded_file($_FILES['swf']['tmp_name'],$upload_path . $filename))
echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>';
else
echo 'An unknown error occured, try again.';
?>
Ok so this is part of the code I found online, with that Im using a simple upload form.
How could I go and put 2 forms on the same page, and the 2 forms upload separately to 2 different folders, in example .png goes to icons/ folder and .swf goes to swf/ folder?
All that with only one button, that will also post other stuff.
the userfile
in $_FILES['userfile']
is set by the value of the name
attribute of the <form>
in your html file.
so:
<form (.....)>
<input type="file" name="userfile0"/>
<input type="file" name="userfile1"/>
</form>
would result in
$_FILES['userfile0']
$_FILES['userfile1']
Please note:
Accepting files from the internet can be dangerous in many ways. make sure you do proper input sanitation and do not store the uploaded files in a web-accessible folder.
精彩评论