D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
thread-self
/
root
/
home
/
shubmkcj
/
urbane.createerp.com
/
ajax
/
Filename :
upload-po-supporting-files.php
back
Copy
<?php ini_set('display_errors',0); error_reporting(0); ob_start(); session_start(); include_once("../config.php"); date_default_timezone_set( "Asia/Calcutta" ); $regDate = date( 'd-M-Y H:i' ); if ( isset( $_POST['po_row_id'] ) ) { $po_row_id = $_POST['po_row_id']; $sql1="SELECT * FROM `purchase_order` WHERE `purchase_order`.`id`='$po_row_id';"; $query1=mysqli_query($conn,$sql1); $count1=mysqli_num_rows($query1); if($count1){ $result1=mysqli_fetch_assoc($query1); $supporting_documents=$result1['supporting_documents']; $po_id=$result1['po_id']; } // File upload configuration $targetDir = "../po-supporting-files/"; $allowTypes = array( 'jpg', 'png', 'jpeg', 'JPG','JPEG','PNG','pdf','PDF' ); $statusMsg = $errorMsg = $insertValuesSQL = $errorUpload = $errorUploadType = ''; $fileNames = array_filter( $_FILES['files']['name'] ); if ( !empty( $fileNames ) ) { $count=1; foreach ( $_FILES['files']['name'] as $key=>$val ) { $rename_po=str_replace("#", '', $po_id); // File upload path $fileName = basename( $_FILES['files']['name'][$key] ); $kaboom1 = explode( ".", $fileName ); $fileExt1 = end( $kaboom1 ); $fileName = "sd-".$rename_po."-".time()."-".$count.".".$fileExt1; $targetFilePath = $targetDir . $fileName; // Check whether file type is valid $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.","; } else { $errorUpload .= $_FILES['files']['name'][$key].' | '; } } else { $errorUploadType .= $_FILES['files']['name'][$key].' | '; } $count++; } // Error message $errorUpload = !empty( $errorUpload )?'Upload Error: '.trim( $errorUpload, ' | ' ):''; $errorUploadType = !empty( $errorUploadType )?'File Type Error: '.trim( $errorUploadType, ' | ' ):''; $errorMsg = !empty( $errorUpload )?'<br/>'.$errorUpload.'<br/>'.$errorUploadType:'<br/>'.$errorUploadType; if ( !empty( $insertValuesSQL ) ) { if(!empty($supporting_documents)){ $insertValuesSQL= trim( $supporting_documents .',' .$insertValuesSQL, ',' ); }else{ $insertValuesSQL = trim( $insertValuesSQL, ',' ); } // Insert image file name into database // $insert = $db->query( "INSERT INTO images (file_name, uploaded_on) VALUES $insertValuesSQL" ); $query = "UPDATE `purchase_order` SET `supporting_documents`='$insertValuesSQL',`upload_supporting_documents_date`='$regDate' WHERE `purchase_order`.`id`='$po_row_id';"; if ( mysqli_query( $conn, $query ) ) { $msg['status'] = "true"; $msg['msg'] = "Files are uploaded successfully."; echo json_encode( $msg ); } else { $msg['status'] = "false"; $msg['msg'] = "Sorry, there was an error uploading your file."; echo json_encode( $msg ); } } else { $msg['status'] = "false"; $msg['msg'] = "Upload failed! "; echo json_encode( $msg ); } } else { $msg['status'] = "false"; $msg['msg'] = 'Please select a file to upload.'; echo json_encode( $msg ); } } ?>