Have got 3 database table as shown below:
Table 1:
id username password
D1 12345 12345
D2 123456 123456
Table 2:
username code address chain
12345 123 ASD WCL
12345 1234 QWE PNS
Table 3:
code jobs week client brand
123 J1 WK01 C1 B1
123 J2 WK01 C1 B2
123 J3 Wk01 C2 B3
When the user logins using username and password, the code related to that specific username is displayed and other than that the jobs related to that specific code as well all together. the query used to display the output is as below:
$sql = "SELECT * FROM tbl_store INNER JOIN tbl_job ON tbl_store.store_code = tbl_job.store_code WHERE username = '$userid'";
There is an HTML form at the end of each block as show in figure below:
I am able to get the preview of the image as well. rest of the codes is all below. PHP.
<form enctype="multipart/form-data" id="form" action="" method="post">
<input type="file" id="image" name="img" onChange="readURL(this);" />
<img id="blah" src="#" alt="your image" /><br/><br/>
<input type="button" value="upload" onclick="javascript:uploadInage();" />
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
//$('#blah').attr('src', e.target.result).width(300).height(340);
$(input).next('img').attr('src', e.target.result).width(300).height(340);
};
reader.readAsDataURL(input.files[0]);
}
}
</script>
<script type="text/javascript">
function uploadInage()
{
var file_data = $('#image').prop('files')[0];
var form_data = new FormData();
form_data.append('file', file_data);
$.ajax({
url: "preview1.php",
dataType: 'text', // what to expect back from the PHP script, if anything
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function (result) {
alert(result)
}
});
</script>
the code above is to preview the image and upload it to the server. file.php:
<?php
$imagePath = "uploads/";
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
$filename = $_FILES["file"]["tmp_name"];
echo "$filename";
$time = time();
move_uploaded_file($filename, $imagePath . $time . '.' . $extension);
echo "File Uploade";
exit;
?>
The problem I am facing is to store the image to the folder and subfolders: For example: I want the image to be uploaded to the folder and sub folder in this pattern:
Client/Brand/J1/Week/Code/Client_Brand_J1_Week_Code.jpg
This is the code that I want to add to the SESSION.
while($row = mysqli_fetch_array($result)){
$target = $upload.'/'.$row['Client'].'/'.$row['Brand'].'/'.$row['jobs'].'/'.$row['store_code'].'/';
$_SESSION[] = $target;
}
How to achieve this?