$message .= "<br>Sorry, only JPG, JPEG, PNG & GIF files are allowed."; } if (!isset($message)) { if (move_uploaded_file($tempName, $directory . "/" . $theFile)) { $path = $directory . "/" . $theFile; $message = "File uploaded successfully"; $query = "INSERT INTO `mp4Pics` (`pic`) VALUES ('" . $theFile . "')"; $result = mysqli_query($link, $query); $query = "INSERT INTO `withImage` (`ifImage`) VALUES (TRUE)"; $result = mysqli_query($link, $query); $imageUploaded = 0; $query = "INSERT INTO `fileUploaders` (`ipAddress`, `imageName`) VALUES ('{$ipAddress}', '{$theFile}')"; $result = mysqli_query($link, $query); } else { $error = $_FILES['image']['error']; $message = getFileUploadError($error); } } // echo $message; } ?> <script> imageUploaded= <?php echo json_encode($imageUploaded); ?> ; localStorage.setItem("imageUploaded", imageUploaded); </script> <?php
/** * Submits the file upload from * @param $moduleComponentId page_modulecomponentid. * @param $moduleName The module which is calling this function. * @param $userId The user who is uploading the files. * @param $maxFileSizeInBytes the maximum permissible size of the files that can be uploaded. * @param $uploadableFileTypesArray An array that contains the file types that has been permitted to be uploaded on that page. * @param $uploadableFieldName The name of the variable used in forms to upload the file * * @return mixed : true if any error is found in the upload otherwise array of filenames uploaded */ function submitFileUploadForm($moduleComponentId, $moduleName, $userId, $maxFileSizeInBytes = false, $uploadableFileTypesArray = false, $uploadFieldName = 'fileUploadField') { if ($maxFileSizeInBytes === false) { $maxFileSizeInBytes = 2 * 1024 * 1024; } if (isset($_FILES[$uploadFieldName]['error'][0])) { $errorCode = $_FILES[$uploadFieldName]['error'][0]; if ($errorCode == UPLOAD_ERR_NO_FILE) { return true; } if ($errorCode != 0) { displayerror("Error in uploading file. " . getFileUploadError($errorCode)); return true; } $uploadedFiles = upload($moduleComponentId, $moduleName, $userId, $uploadFieldName, $maxFileSizeInBytes, $uploadableFileTypesArray); if (is_array($uploadedFiles) && count($uploadedFiles) > 0) { displayinfo("Successfully uploaded file(s) " . join($uploadedFiles, "; ") . "."); } return $uploadedFiles; } else { return true; } }