I have an Android Application and I am currently able to upload CSV files to our online server. Everything works fine and I am able to upload the files without a hitch. However, I want to autosort the files into folders based on the date that they're uploaded.
Here is my code:
HttpURLConnection conn = null;
conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true); // Allow Inputs
conn.setDoOutput(true); // Allow Outputs
conn.setUseCaches(false); // Don't use a Cached Copy
conn.setRequestMethod("POST");
conn.setRequestProperty("Connection", "Keep-Alive");
conn.setRequestProperty("ENCTYPE", "multipart/form-data");
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
conn.setRequestProperty("uploaded_file", selectedFilePath);
conn.setRequestProperty("date", date);
dos = new DataOutputStream(conn.getOutputStream());
//then I write the DataOutputStream with the CSV Data and upload it
//this is all wrapped in an Async-Task
As you can see, I added in the date
parameter, and then here is what I do in my PHP:
<?php
$file_path = $_FILES['date'] . "/";
if (!is_dir($file_path)) {
mkdir($file_path, 0755, true);
}
// $file_path = "uploads/";
$file_path = $file_path . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path)) {
echo "success";
}
else{
echo "fail";
}
?>
I am trying to get the date
parameter, so that it will upload to the said date instead of the default upload/
folder.
I've also tried the $_GET['date']
as well as $_POST['date']
but nothing happened. No folders get created, no files get uploaded.