Skip to content

Instantly share code, notes, and snippets.

@MrRaindrop
Created October 11, 2014 13:56
Show Gist options
  • Save MrRaindrop/dac8707f03c615c66316 to your computer and use it in GitHub Desktop.
Save MrRaindrop/dac8707f03c615c66316 to your computer and use it in GitHub Desktop.
php: upload file 2
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>testUpload2</title>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"
enctype="multipart/form-data">
<label form="name">Name:</label><br/>
<input type="text" name="name" value="" /><br/>
<label form="classnote">Class notes:</label><br/>
<input type="file" name="classnotes" value="" /><br/>
<input type="submit" name="submit" value="submit notes">
</form>
<?php
define("FILEREPOSITORY", __DIR__ . "\\classnotes\\");
if (isset($_FILES['classnotes'])) {
if (is_uploaded_file($_FILES['classnotes']['tmp_name'])) {
if ($_FILES['classnotes']['type'] != 'application/pdf') {
echo "<p>Class notes must be uploaded in PDF format.</p>";
} else {
$name = $_POST['name'];
$result = move_uploaded_file($_FILES['classnotes']['tmp_name'],
FILEREPOSITORY . $name . ".pdf");
if ($result == 1) {
echo "<p>File successfully uploaded.</p>";
} else {
echo "<p>There was a problem uploading the file.</p>";
}
}
}
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment