I want to be able to upload 2 files using the same form. The first file will be a jpg of a certain size. If it's not the correct size it needs to be resized so that it is. The second file will be a zip/rar archive file.
Once uploaded they should both be renamed so that they have the same name and, the info entered into a database.
I have no problem with the actual uploading & inserting into the database but, any suggestions or tutorials on combining the rest appreciated.
Multiple file uploads
Moderator: General Moderators
Code: Select all
<?php
$path_to_file = "templates/$title";
$files = $HTTP_POST_FILES['files'];
if (!ereg("/$", $path_to_file))
$path_to_file = $path_to_file."/";
foreach ($files['name'] as $key=>$name)
{
if ($files['size'][$key])
{
// clean up file name
$name = ereg_replace("[^a-z0-9._]", "",str_replace(" ", "_",str_replace("%20", "_", strtolower($name))));
$location = $path_to_file.$name;
while (file_exists($location))
$location .= ".copy";
copy($files['tmp_name'][$key],$location);
unlink($files['tmp_name'][$key]);
echo "\n
Successfully uploaded file: $name.";
}
}
?>Then the database thing is simple query
It's pretty simple, just do the same thing you would with one upload and then repeat. Heres an example.
form.php
upload.php
You can then manipulate them however you want.
Edit:
Damn, Basdog beat me to it
form.php
Code: Select all
<form action="upload.php" method="post">
<input type="file" name="image">
<input type="file" name="zipfile">
<input type='submit' name='submit' value='Submit'>
</form>Code: Select all
<?php
echo $_FILES['image']['name']; //echos something like somepicture.jpg
echo $_FILES['zipfile']['name']; //echos seomthing like data.zip
?>Edit:
Damn, Basdog beat me to it