Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 KB | None | 0 0
  1. <?php include 'header.php'; ?>
  2.  
  3. // <script type="text/javascript" >
  4. // $(document).ready(function() {
  5. // $('#imageform').on('submitPhoto', function(){
  6. // $("#preview").html('<div class="progress progress-striped active"><div class="bar" style="width: 40%;"></div></div>');
  7. // $("#imageform").ajaxForm({
  8. // target: '#preview'
  9. // }).submit();
  10.  
  11. // });
  12. // });
  13. // </script>
  14. <script>
  15. $(function(){
  16. $('#imageform').on('submitPhoto', function(e){
  17. e.preventDefault();
  18. $.ajax({
  19. url: 'ajaximage.php',
  20. type: 'POST',
  21. data: $('#imageform').serialize(),
  22. success: function(data){
  23. $('submit.php/#photoModal').modal('hide');
  24. $('submit.php/#confirm').modal('show');
  25. }
  26. });
  27. });
  28. });
  29. </script>
  30.  
  31. <a href="#photoModal" role="button" class="btn" data-toggle="modal">Submit a Photo</a>
  32.  
  33. <!-- Modal -->
  34. <div id="photoModal" class="modal hide fade"
  35. tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  36.  
  37. <div class="modal-header">
  38. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  39. <h3 id="myModalLabel">Submit Your Media</h3>
  40. </div>
  41.  
  42. <form id="imageform" method="post" enctype="multipart/form-data">
  43.  
  44. <div class="modal-body">
  45.  
  46. Upload your image
  47. <input type="file" name="photoimg" id="photoimg" />
  48.  
  49. <div id="preview">
  50. </div>
  51.  
  52. </div>
  53.  
  54. <div class="modal-footer">
  55. <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
  56. <input type="submit" id="photoSubmit" name="submitPhoto" value="Submit" class="btn btn-primary">
  57. </div>
  58.  
  59. </form>
  60.  
  61. </div>
  62.  
  63. <!-- Modal -->
  64. <div id="confirm" class="modal hide fade"
  65. tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  66.  
  67. <div class="modal-header">
  68. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
  69. <h3 id="myModalLabel">Media Submitted</h3>
  70. </div>
  71.  
  72. <div class="modal-body">
  73.  
  74. <p>Success</p>
  75. <ul>
  76. <li><?php echo $name; ?></li>
  77. <li><?php echo $type; ?></li>
  78. <li><?php echo $size; ?></li>
  79. </ul>
  80.  
  81. </div>
  82.  
  83. <div class="modal-footer">
  84. <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
  85. <input type="submit" name="okay" value="Okay" class="btn btn-primary">
  86. </div>
  87. </div>
  88.  
  89. <?php
  90. include('db.php');
  91. session_start();
  92. $session_id='1'; //$session id
  93. $path = "uploads/";
  94.  
  95. $valid_formats = array("jpg", "png", "gif", "bmp");
  96. if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
  97. {
  98. $name = $_FILES['photoimg']['name'];
  99. $size = $_FILES['photoimg']['size'];
  100.  
  101. if(strlen($name))
  102. {
  103. list($txt, $ext) = explode(".", $name);
  104. if(in_array($ext,$valid_formats))
  105. {
  106. if($size<(1024*1024))
  107. {
  108. $actual_image_name = time().substr(str_replace(" ", "_", $txt), 5).".".$ext;
  109. $tmp = $_FILES['photoimg']['tmp_name'];
  110. if(move_uploaded_file($tmp, $path.$actual_image_name))
  111. {
  112. mysql_query("UPDATE submissions SET filename='$actual_image_name' ");
  113.  
  114. echo "<img src='uploads/".$actual_image_name."' class='preview'>";
  115. }
  116. else
  117. echo "failed";
  118. }
  119. else
  120. echo "Image file size max 1 MB";
  121. }
  122. else
  123. echo "Invalid file format..";
  124. }
  125.  
  126. else
  127. echo "Please select image..!";
  128.  
  129. exit;
  130. }
  131. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement