Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $pdo = new PDO("mysql:host=localhost;dbname=_fantapc", '_fpcroot', 'password');
- if(isset($_POST['addcard'])) {
- $cardname = $_POST['card_input'];
- $rarity = $_POST['rarity_input'];
- $image = $_FILES['file']['name'];
- $query = $pdo->prepare("INSERT INTO cards (name,rarity,img) VALUES (:name,:rarity,:img)");
- $query->bindValue(":name", $cardname, PDO::PARAM_STR);
- $query->bindValue(":rarity", $rarity, PDO::PARAM_STR);
- $query->bindValue(":img", $image, PDO::PARAM_STR);
- $query->execute();
- if ($_FILES["file"]["error"] > 0) {
- echo "Error: " . $_FILES["file"]["error"] . "<br>";
- }
- else {
- echo "Upload: " . $_FILES["file"]["name"] . "<br>";
- echo "Type: " . $_FILES["file"]["type"] . "<br>";
- echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
- echo "Stored in: " . $_FILES["file"]["tmp_name"];
- }
- $allowedExts = array("gif", "jpeg", "jpg", "png");
- $temp = explode(".", $_FILES["file"]["name"]);
- $extension = end($temp);
- if ((($_FILES["file"]["type"] == "image/gif")
- || ($_FILES["file"]["type"] == "image/jpeg")
- || ($_FILES["file"]["type"] == "image/jpg")
- || ($_FILES["file"]["type"] == "image/pjpeg")
- || ($_FILES["file"]["type"] == "image/x-png")
- || ($_FILES["file"]["type"] == "image/png"))
- && in_array($extension, $allowedExts)) {
- if ($_FILES["file"]["error"] > 0) {
- echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
- }
- else {
- echo "Upload: " . $_FILES["file"]["name"] . "<br>";
- echo "Type: " . $_FILES["file"]["type"] . "<br>";
- echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
- echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
- if (file_exists("upload/" . $_FILES["file"]["name"])) {
- echo $_FILES["file"]["name"] . " already exists. ";
- }
- else {
- move_uploaded_file($_FILES["file"]["tmp_name"],
- "upload/" . $_FILES["file"]["name"]);
- echo "Stored in: " . "/opt/lampp/htdocs/andreas/fantasicapricecheck/upload/" . $_FILES["file"]["name"];
- }
- }
- }
- else {
- echo "Invalid file";
- }
- }
- ?>
- <h1>Add cards</h1>
- <form action="index.php?page=addcards" method="post" enctype="multipart/form-data">
- <table>
- <tr>
- <td>cardname: </td><td> <input type="text" name="card_input"></td></tr>
- <tr>
- <td>rarity: </td><td> <select name="rarity_input">
- <option value="1">1 star</option>
- <option value="2">2 star</option>
- <option value="3">3 star</option>
- <option value="4">4 star</option>
- <option value="5">5 star</option>
- <option value="6">6 star</option>
- <option value="7">7 star</option>
- </select></td></tr>
- <tr>
- <td>image: </td><td><input type="file" name="file" id="file"></td></tr>
- <tr>
- <td></td><td>
- <input type="hidden" name="addcard" value="1">
- <input type="submit" value="add card!"></td>
- </tr></table></form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement