Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(isset($_POST['submit'])){//When the submit button is clicked
- $poem=($_POST['poem']);
- $fname=($_POST['fname']);
- $ycode=($_POST['ycode']);
- addData($poem, $fname, $ycode);
- echo "<script>setTimeout(\"location.href = 'index.php';\",2000);</script>";
- }
- function uploadImg(){//upload a selected image
- $target_dir = "uploads/";//user must create this directory on their server
- $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
- $uploadOk = 1;
- $imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
- // Check if image file is a actual image or fake image
- $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
- if($check !== false) {
- //echo "File is an image - " . $check["mime"] . ".";
- $uploadOk = 1;
- } else {
- //echo "File is not an image.";
- $uploadOk = 0;
- }
- // Check if file already exists
- if (file_exists($target_file)) {
- //echo "Sorry, file already exists.";
- $uploadOk = 0;
- }
- // Check file size
- if ($_FILES["fileToUpload"]["size"] > 5000000000) {
- //echo "Sorry, your file is too large.";
- $uploadOk = 0;
- }
- // Allow certain file formats
- $imageFileType=strtolower($imageFileType);
- if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
- && $imageFileType != "gif" ) {
- //echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
- $uploadOk = 0;
- }
- if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
- //echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
- } else {
- $uploadOk=0;
- }
- return $uploadOk;
- }
- function uploadAud(){//upload a selected audio
- $target_dir = "uploads2/";//user must create this directory on their server
- $target_file = $target_dir . basename($_FILES["fileToUpload2"]["name"]);
- $uploadOk = 1;
- $audioFileType = pathinfo($target_file,PATHINFO_EXTENSION);
- // Check if file already exists
- if (file_exists($target_file)){
- echo "Sorry, file already exists.";
- $uploadOk = 0;
- }
- // Check file size
- if ($_FILES["fileToUpload2"]["size"] > 5000000000) {
- echo "Sorry, your file is too large.";
- $uploadOk = 0;
- }
- // Allow certain file formats
- $audioFileType=strtolower($audioFileType);
- if($audioFileType != "wav" && $audioFileType != "mp3" && $audioFileType != "wma"
- && $audioFileType != "mp4" ) {
- echo "Sorry, only wav, mp3, wma & mp4 files are allowed.";
- $uploadOk = 0;
- }
- if (move_uploaded_file($_FILES["fileToUpload2"]["tmp_name"], $target_file)) {
- //echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
- } else {
- $uploadOk=0;
- }
- return $uploadOk;
- }
- function addData($poem, $fname, $ycode){//function that compiles everything together
- mysql_connect('localhost', 'root', '');//calls uploadImg() and uploadAud()
- mysql_select_db('searcher');
- $img="{$_FILES['fileToUpload']['name']}";;
- $aud="{$_FILES['fileToUpload2']['name']}";
- $sql="INSERT INTO entries VALUES(null, '$poem', '$fname', '$ycode', '$img', '$aud')";
- if((uploadImg())&&(uploadAud())){
- $result=mysql_query($sql);
- echo "Upload Success!";
- }else{
- echo "Error: Upload failure! Try again";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement