Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>Demo</title>
- <link href="style.css" rel="stylesheet" />
- </head>
- <body>
- <h2>Demo upload</h2>
- <?php
- define('DB_HOST', 'localhost');
- define('DB_USER', 'root');
- define('DB_PASSWORD', 'pass');
- define('DB_NAME', 'mydb');
- define('UPLOADPATH', 'images/');
- define('MAXFILESIZE', 32768);
- if(isset($_POST['submit'])){
- $name = trim($_POST['name']);
- $score = trim($_POST['score']);
- $screenshot = $_FILES['screenshot']['name'];
- $screenshot_type = $_FILES['screenshot']['type'];
- $screenshot_size = $_FILES['screenshot']['size'];
- echo $name.'<br>';
- echo $score.'<br>';
- echo $screenshot_type.'<br>';
- if(!empty($name) && !empty($score) && !empty($screenshot)){
- if(($screenshot_type == 'image/gif' || $screenshot_type == 'image/jpeg'
- || $screenshot_type == 'image/pjpeg' || $screenshot_type == 'image/png')
- && ($screenshot_size > 0 && $screenshot_size <= MAXFILESIZE)){
- if($_FILES['screenshot']['error'] == 0){
- $target = UPLOADPATH.$screenshot;
- // if(move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)){
- $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
- or die('Error connecting to MySQL Server.');
- $query = "INSERT INTO guitarwars VALUES (0, NOW(), '$name', '$score',
- '$screenshot')";
- mysqli_query($dbc, $query);
- echo '<p>Thanks for adding your new high score!</p>';
- echo '<p><strong>Name:</strong> '.$name.'<br>';
- echo '<strong>Score:</strong> '.$score.'<br>';
- echo '<img src="'.UPLOADPATH.$screenshot.'" alt="Score image" /></p>';
- echo '<p><a href="index.php"><< Back to high scores</a></p>';
- $name = "";
- $score = "";
- mysqli_close($dbc);
- //} else {
- // echo '<p class="error">Sorry, there was a problem uploading your screen shot image.</p>';
- //}
- } else echo 'Error';
- } else {
- echo '<p class="error">The screen shot must be a GIF, JPEG, or PNG image file no '.
- 'greater than '.(MAXFILESIZE / 1024).' KB in size.</p>';
- }
- //@unlink($_FILES['screenshot']['tmp_name']);
- }else{
- echo '<p class="error">Please enter all of the information to add your
- high score.</p>';
- }
- }
- ?>
- <hr />
- <form name="upload" enctype="multipart/form-data" method="post"
- action="<?php echo $_SERVER['PHP_SELF']; ?>">
- <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAXFILESIZE; ?>" />
- <label for="name">Name:</label>
- <input type="text" id="name" name="name"
- value="<?php if(!empty($name)) echo $name; ?>" /><br>
- <label for="score">Score:</label>
- <input type="text" id="score" name="score"
- value="<?php if(!empty($score)) echo $score; ?>" /><br>
- <label for="screenshot">Screen shot:</label>
- <input type="file" id="screenshot" name="screenshot" />
- <hr />
- <input type="submit" name="submit" value="Add" />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement