Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['submit'])){//When the submit button is clicked
  3. $poem=($_POST['poem']);
  4. $fname=($_POST['fname']);
  5. $ycode=($_POST['ycode']);
  6. addData($poem, $fname, $ycode);
  7. echo "<script>setTimeout(\"location.href = 'index.php';\",2000);</script>";
  8.  
  9. }
  10.  
  11. function uploadImg(){//upload a selected image
  12. $target_dir = "uploads/";//user must create this directory on their server
  13. $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
  14. $uploadOk = 1;
  15. $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
  16. // Check if image file is a actual image or fake image
  17. $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  18. if($check !== false) {
  19. //echo "File is an image - " . $check["mime"] . ".";
  20. $uploadOk = 1;
  21. } else {
  22. //echo "File is not an image.";
  23. $uploadOk = 0;
  24. }
  25. // Check if file already exists
  26. if (file_exists($target_file)) {
  27. //echo "Sorry, file already exists.";
  28. $uploadOk = 0;
  29. }
  30. // Check file size
  31. if ($_FILES["fileToUpload"]["size"] > 5000000000) {
  32. //echo "Sorry, your file is too large.";
  33. $uploadOk = 0;
  34. }
  35. // Allow certain file formats
  36. $imageFileType=strtolower($imageFileType);
  37. if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
  38. && $imageFileType != "gif" ) {
  39. //echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  40. $uploadOk = 0;
  41. }
  42. if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
  43. //echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
  44. } else {
  45. $uploadOk=0;
  46. }
  47. return $uploadOk;
  48. }
  49.  
  50. function uploadAud(){//upload a selected audio
  51. $target_dir = "uploads2/";//user must create this directory on their server
  52. $target_file = $target_dir . basename($_FILES["fileToUpload2"]["name"]);
  53. $uploadOk = 1;
  54. $audioFileType = pathinfo($target_file,PATHINFO_EXTENSION);
  55. // Check if file already exists
  56. if (file_exists($target_file)){
  57. echo "Sorry, file already exists.";
  58. $uploadOk = 0;
  59. }
  60. // Check file size
  61. if ($_FILES["fileToUpload2"]["size"] > 5000000000) {
  62. echo "Sorry, your file is too large.";
  63. $uploadOk = 0;
  64. }
  65. // Allow certain file formats
  66. $audioFileType=strtolower($audioFileType);
  67. if($audioFileType != "wav" && $audioFileType != "mp3" && $audioFileType != "wma"
  68. && $audioFileType != "mp4" ) {
  69. echo "Sorry, only wav, mp3, wma & mp4 files are allowed.";
  70. $uploadOk = 0;
  71. }
  72. if (move_uploaded_file($_FILES["fileToUpload2"]["tmp_name"], $target_file)) {
  73. //echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
  74. } else {
  75. $uploadOk=0;
  76. }
  77.  
  78. return $uploadOk;
  79. }
  80.  
  81. function addData($poem, $fname, $ycode){//function that compiles everything together
  82. mysql_connect('localhost', 'root', '');//calls uploadImg() and uploadAud()
  83. mysql_select_db('searcher');
  84. $img="{$_FILES['fileToUpload']['name']}";;
  85. $aud="{$_FILES['fileToUpload2']['name']}";
  86. $sql="INSERT INTO entries VALUES(null, '$poem', '$fname', '$ycode', '$img', '$aud')";
  87.  
  88. if((uploadImg())&&(uploadAud())){
  89. $result=mysql_query($sql);
  90. echo "Upload Success!";
  91. }else{
  92. echo "Error: Upload failure! Try again";
  93. }
  94. }
  95. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement