Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4328724
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:43:29+00:00 2026-05-21T09:43:29+00:00

I created some code to handle basic file upload from a java client to

  • 0

I created some code to handle basic file upload from a java client to a php server, but I’m having some issues with the naming and directory creation. Here is the important parts of the code:

The method I use to upload the file:

public static void uploadWithInfo(Uri uri, String title, String artist, String description) {
    try {
        String path = uri.getPath();
        File file = new File(path);
        URL url = new URL("http://**********/upload.php?title="+title+"&artist="+artist+"&description="+description);
        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
        connection.setDoOutput(true);
        connection.setRequestMethod("POST");
        OutputStream os = connection.getOutputStream();

        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
        int totalbytes = bis.available();

        for(int i = 0; i < totalbytes; i++) {
            os.write(bis.read());
        }
        os.close();

        BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String serverResponse = "";
        String response = "";

        while((response = reader.readLine()) != null) {
            serverResponse = serverResponse + response;
        }
        reader.close();
        bis.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

It’s just supposed to upload an audio file. The user inputs the artist, title, and a very short description if necessary. The actual file is uploaded just fine so I don’t think any more java is necessary. Here is the code on the php end:

<?php

$uploadBase = "music/";
$uploadFolder = $_GET['artist']+"/";
$uploadFileName = $_GET['title'];
$uploadFileDescription = $_GET['description'];
$uploadPath = $uploadBase.$uploadFolder.$uploadFileName."%%D%%=".$uploadFileDescription.".mp3";

if(!is_dir($uploadBase)) {
    mkdir($uploadBase);
}

if(!is_dir($uploadFolder)) {
    mkdir($uploadFolder);
}

$incomingData = file_get_contents('php://input');

if(!$incomingData) {
    die("No data.");
}

$fh = fopen($uploadPath, 'w') or die("Error opening path.");
fwrite($fh, $incomingData) or die("Error writing file.");
fclose($fh) or die("Error closing shop.");

echo "Success!";

?>

So I get all of the inputted values for title, artist, and description. Then I create 2 directories if they don’t already exist: one for music and one for the artist the uploader input. Then I create a path of base(music)/folder(artist)/filename(title)”code to let me parse description”(%%D%%).mp3.

So a song Billie Jean by Michael Jackson with a description “favorite” should have a path of

music/Michael Jackson/Billie%20Jean%%D%%favorite.mp3

What I get however, is:

music/0Billie%%D%%=

The directory for artist is not created, there is a weird 0 before the title (which only includes the first word), and the description doesn’t show.

I don’t really know where I went wrong, can anyone give me some insight? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:43:29+00:00Added an answer on May 21, 2026 at 9:43 am

    Turns out it was a stupid error with some related php code. Sorry to trouble you all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a class library in VB .NET. Some code in the library
I have created a report in MS Access report and write some VBA code
I have some code on my PHP powered site that creates a random hash
I am trying to create a countdown using javascript. I got some code from
I'd like to write some (java) code that takes a PDF document, and creates
Wrote up a basic file handler for a Java Homework assignment, and when I
I am writing on a small tcp chat server, but I am encountering some
I have some code that creates a new site in SharePoint. Upon browsing to
I have some code which I did not originally create that uses _beginthreadex and
Could anyone could point me to some code/give me ideas on how to create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.