Skip to content
Snippets Groups Projects
Commit 226795b7 authored by Vidmantas Naravas's avatar Vidmantas Naravas
Browse files

added upload file script

parent 161b0aa1
No related merge requests found
......@@ -42,6 +42,9 @@ case 'new_admin' :
case 'edit_admin' :
include 'admin/edit_admin.php';
break;
case 'add_image' :
include 'admin/add_image.php';
break;
case 'delete_admin' :
include 'admin/delete_admin.php';
break;
......
<?php
/* confirm_logged_in(); */
$content = "<h1>Upload an image</h1>";
$action = htmlspecialchars($_SERVER["PHP_SELF"]."?page=add_image");
$form_html = "<form enctype='multipart/form-data' action='".$action."' method='POST' >
Select image to upload:
<br/>
<br/>
<input type='file' name='fileToUpload' id='fileToUpload'>
<br>
<br>
<input type='submit' value='Upload Image' name='submit'>
</form>";
// append form HTML to content string
$content .= $form_html;
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, 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.";
}
}
}
echo($content);
?>
......@@ -5,6 +5,7 @@
<li><a href="?page=manage" title="Manage admins">Manage Admins</a></li>
<li><a href="?page=add_artist" title="">Add Artists</a></li>
<li><a href="?page=add_record" title="Add record">Add Record</a></li>
<li><a href="?page=add_image" title="Add record">Upload Image</a></li>
<li><a href="?page=logout">Logout</a></li>
</ul>
</nav>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment