Skip to content
Snippets Groups Projects
Commit db374087 authored by Jeremy Coulson's avatar Jeremy Coulson
Browse files

added some rudimentary code for uploading files and having it store in the folder called uploads

parent 1b87a73f
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,14 @@
<br>
Coming soon...
<form action="upload.php" method="post" enctype="multipart/form-data">
Upload your code below.
<br>
<br>
<input class="fileupload" type="file" id="myToUpload" name="fileToUpload">
<br>
<input type="submit" value="Upload Code" name="submit">
</form>
</main>
</div>
......
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Allow certain file formats
if($imageFileType != "cpp") {
echo "Sorry, only C++ files are allowed. ";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment