ajax_upload_image_action.php

 avatar
unknown
php
3 years ago
1.1 kB
6
Indexable
<?php
	//ajax action file
	include('db/conn.php');
	include('admin_functions.php');
	include('admin_model.php');

	//print "<pre>";
	//print_r($_POST);					
	//print "</pre>";

	$selected_worker1   = $_POST['data2'];
	$description      	= $_POST['data1'];
	$filename 			= $_FILES['file']['name'];

	// Location
	$dttm = date('Ymdhis');
	$location = 'upload/'.$dttm.$filename;
	
	// file extension
	$file_extension = pathinfo($location, PATHINFO_EXTENSION);
	$file_extension = strtolower($file_extension);

	// Valid image extensions
	$image_ext = array("jpg","png","jpeg","gif");
	$response = 0;
	if(in_array($file_extension,$image_ext))
	{
	  
	  // Upload file
		if(move_uploaded_file($_FILES['file']['tmp_name'],$location))
		{
			$response = $location;
			
			$array_data 	= array(
									"worker_profile_id" => $selected_worker1,
									"description" 		=> $description,
									"datetime" 			=> $dttm,
									"upload_file"		=> $location,
								);
			
			
			$tablename	= "upload_data";	
			$res = insert_data($tablename,$array_data);
			print $response;
		
		}
	}

	echo $response;
Editor is loading...