0

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:

<?php $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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

My html file is: <form action="upload.php" method="post" enctype="multipart/form-data"> <p> <label for="file">Select a file:</label> <input type="file" name="swf" id="file"> <br /> <label for="file">Select a file:</label> <input type="file" name="png" id="file"> <br /> <button onclick="this.disabled=true">Upload File</button> <p> </form> So where would I add the $_FILES['swf'] and $_FILES['png']? Here? if(move_uploaded_file($_FILES['swf']['tmp_name'],$upload_path . $filename)) If yea, how can I do so?
You are on the right track. start experimenting and you will eventually get there. just take it one step at the time.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.