在这里,这应该就是你所需要的!
index.html格式为:
<form action="RejoinReq.php" method="post" enctype="multipart/form-data">
Attachment(s): <input type="file" name="file[]" id="file" maxlength="500" accept="application/pdf,image/*" multiple>
<input type="submit" name="submit" value="Request">
</form>
和接收RejoinReq.php:
<?php
// config
$upload_dir = '/var/www/html/upload'; // set your upload dir
$max_size = 1048576; // max file size: 1 MB
$allow_override = FALSE; // allow uploading files overriding existing ones
$valid_exts = array( // allowed extensions
'gif',
'jpeg',
'jpg',
'png',
'pdf',
);
$valid_types = array(
'image/gif',
'image/jpeg',
'image/jpg',
'image/pjpeg',
'image/x-png',
'image/png',
'text/pdf',
'application/pdf',
);
// reorganize files array
$files = array();
foreach ($_FILES['file'] as $attr => $arr) {
foreach ($arr as $k => $v) {
$files[$k][$attr] = $v;
}
}
// loop thru files
foreach ($files as $file) {
$status = 'Failure';
// get extension
$extension = pathinfo($file['name'], PATHINFO_EXTENSION);
// make sure extension and type are not empty
if ( ! (strlen($extension) && strlen($file['type']))) {
$msg = 'File extension or type not found';
}
else {
// make sure extension and type are allowed
if ( ! (in_array($file['type'], $valid_types) && in_array($extension, $valid_exts))) {
$msg = "Extension '$extension' or file type '$file[type]' is not permitted";
}
else {
// make sure file is not empty
if ( ! $file['size']) {
$msg = 'File seems to be empty (0 KB)';
}
else {
// make sure file is not too large
if ($file['size'] > $max_size) {
$msg = 'File is too large (' . ceil($file['size'] / 1024) . 'kB > ' . floor($max_size / 1024) . 'kB)';
}
else {
// rename file here as you need
$target = "$upload_dir/$_SESSION[myusername]Rejoin.$file[name]";
// make sure files don't override
if ( ! $allow_override && file_exists($target)) {
$msg = "File already exists";
}
else {
// no other errors
if ($file['error'] > 0) {
$msg = "Unknown upload error (Code: $file[error])";
}
else {
// attempt uploading
if ( ! move_uploaded_file($file['tmp_name'], $target)) {
$msg = 'Upload failed. Folder issues?';
}
else {
// all good!
$msg = 'Upload successful!';
$status = 'Success';
}
}
}
}
}
}
}
$out[] = "$file[name]: $status. $msg";
}
echo implode("\n", $out);
/* End of file */