Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(isset($_POST['submit'])){
- // Include the database configuration file
- include_once 'dbConfig.php';
- $targetDir = "slike/";
- $allowTypes = array('jpg','png','jpeg','gif');
- $arr=array_filter($_FILES['files']['name']);
- $statusMsg = $errorMsg = $insertValuesSQL = $errorUpload = $errorUploadType = '';
- if(!empty($arr)){
- foreach($_FILES['files']['name'] as $key=>$val){
- $fileName = basename($_FILES['files']['name'][$key]);
- $targetFilePath = $targetDir . $fileName;
- $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);
- if(in_array($fileType, $allowTypes)){
- // Upload file to server
- if(move_uploaded_file($_FILES["files"]["tmp_name"][$key], $targetFilePath)){
- // Image db insert sql
- $insertValuesSQL .= "('".$fileName."', NOW()),";
- }else{
- $errorUpload .= $_FILES['files']['name'][$key].', ';
- }
- }else{
- $errorUploadType .= $_FILES['files']['name'][$key].', ';
- }
- }
- if(!empty($insertValuesSQL)){
- $insertValuesSQL = trim($insertValuesSQL,',');
- $insert = $db->query("INSERT INTO images (ime, izbacena) VALUES $insertValuesSQL");
- if($insert){
- $errorUpload = !empty($errorUpload)?'Upload Error: '.$errorUpload:'';
- $errorUploadType = !empty($errorUploadType)?'File Type Error: '.$errorUploadType:'';
- $errorMsg = !empty($errorUpload)?'<br/>'.$errorUpload.'<br/>'.$errorUploadType:'<br/>'.$errorUploadType;
- $statusMsg = "Files are uploaded successfully.".$errorMsg;
- }else{
- $statusMsg = "Sorry, there was an error uploading your file.";
- }
- }
- }else{
- $statusMsg = 'Please select a file to upload.';
- }
- // Display status message
- echo $statusMsg;
- }
- ?>
Add Comment
Please, Sign In to add comment