Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. <?php
  2.  
  3. $uploadDir = 'images/'; //Image Upload Folder
  4. if(isset($_POST['Submit']))
  5. {
  6. $title = mysql_real_escape_string($_POST['title']);
  7. $fileName = $_FILES['Photo']['name'];
  8. $tmpName = $_FILES['Photo']['tmp_name'];
  9. $fileSize = $_FILES['Photo']['size'];
  10. $fileType = $_FILES['Photo']['type'];
  11. $filePath = $uploadDir . $fileName;
  12. $result = move_uploaded_file($tmpName, $filePath);
  13. if (!$result) {
  14. echo "Error uploading file";
  15. exit;
  16. }
  17. if(!get_magic_quotes_gpc())
  18. {
  19. $fileName = addslashes($fileName);
  20. $filePath = addslashes($filePath);
  21. }
  22. $query = "INSERT INTO images(title,image) VALUES ('".$title."','".$filePath."')";
  23. mysql_query($query) or die (mysql_error());
  24. }
  25. ?>
  26.  
  27. <form name="Image" enctype="multipart/form-data" action="image.php" method="POST">
  28. <input type="text" name="title" id="title" value=""><br/><br/>
  29. <input type="file" name="Photo" size="20" accept="image/gif, image/jpeg, image/x-ms-bmp, image/x-png"><br/>
  30. <INPUT type="submit" class="button" name="Submit" value=" Submit ">
  31. </form>
  32.  
  33. $('form').submit(function(event) {
  34. var file = $('input[type=file]').val();
  35.  
  36. if ( ! file) {
  37. alert('The file is required.');
  38. event.preventDefault();
  39. return;
  40. }
  41.  
  42. if (file.match(/.(?:jpeg|jpg|gif)$/)) {
  43. alert('Image files only!');
  44. event.preventDefault();
  45. }
  46.  
  47. });
  48.  
  49. $('form').submit(function(event) {
  50. var file = $('input[type=file]').prop('files')[0];
  51.  
  52. if ( ! file) {
  53. alert('The file is required.');
  54. event.preventDefault();
  55. return;
  56. }
  57.  
  58. var mime = file.type;
  59.  
  60. if (mime != 'text/jpeg' || mime != 'application/gif') {
  61. alert('Image only!');
  62. event.preventDefault();
  63. }
  64.  
  65. });
  66.  
  67. if ($('#title').val() === '') {
  68. // error code
  69. }
  70.  
  71. var extension = $('input[name=Photo]').val().split('.').pop();
  72. if (extension !== "gif" && extension !== "jpg") {
  73. // error code
  74. }
  75.  
  76. $('form').submit(function () {
  77. var error = false;
  78. // error checking here
  79.  
  80. if (error) {
  81. return false;
  82. }
  83. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement