Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $uploadDir = 'images/'; //Image Upload Folder
- if(isset($_POST['Submit']))
- {
- $title = mysql_real_escape_string($_POST['title']);
- $fileName = $_FILES['Photo']['name'];
- $tmpName = $_FILES['Photo']['tmp_name'];
- $fileSize = $_FILES['Photo']['size'];
- $fileType = $_FILES['Photo']['type'];
- $filePath = $uploadDir . $fileName;
- $result = move_uploaded_file($tmpName, $filePath);
- if (!$result) {
- echo "Error uploading file";
- exit;
- }
- if(!get_magic_quotes_gpc())
- {
- $fileName = addslashes($fileName);
- $filePath = addslashes($filePath);
- }
- $query = "INSERT INTO images(title,image) VALUES ('".$title."','".$filePath."')";
- mysql_query($query) or die (mysql_error());
- }
- ?>
- <form name="Image" enctype="multipart/form-data" action="image.php" method="POST">
- <input type="text" name="title" id="title" value=""><br/><br/>
- <input type="file" name="Photo" size="20" accept="image/gif, image/jpeg, image/x-ms-bmp, image/x-png"><br/>
- <INPUT type="submit" class="button" name="Submit" value=" Submit ">
- </form>
- $('form').submit(function(event) {
- var file = $('input[type=file]').val();
- if ( ! file) {
- alert('The file is required.');
- event.preventDefault();
- return;
- }
- if (file.match(/.(?:jpeg|jpg|gif)$/)) {
- alert('Image files only!');
- event.preventDefault();
- }
- });
- $('form').submit(function(event) {
- var file = $('input[type=file]').prop('files')[0];
- if ( ! file) {
- alert('The file is required.');
- event.preventDefault();
- return;
- }
- var mime = file.type;
- if (mime != 'text/jpeg' || mime != 'application/gif') {
- alert('Image only!');
- event.preventDefault();
- }
- });
- if ($('#title').val() === '') {
- // error code
- }
- var extension = $('input[name=Photo]').val().split('.').pop();
- if (extension !== "gif" && extension !== "jpg") {
- // error code
- }
- $('form').submit(function () {
- var error = false;
- // error checking here
- if (error) {
- return false;
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement