0

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.

halfer
  • 19,824
  • 17
  • 99
  • 186
Razgriz
  • 7,179
  • 17
  • 78
  • 150

1 Answers1

0

you can use

$_POST['date']

to get date from post fields.

Amir Mohsen
  • 853
  • 2
  • 9
  • 23
  • I do not know anything about android development but in php for access URL param we use $_GET , for access form param use $_POST, for access file while sending with form use $_FILES in this case i see you use conn.setRequestMethod("POST"); i found it your send request as post try it : http://stackoverflow.com/questions/9767952/how-to-add-parameters-to-httpurlconnection-using-post – Amir Mohsen Jan 08 '17 at 11:02