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

  • Home
  • SEARCH
  • 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 9193729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:13:58+00:00 2026-06-17T21:13:58+00:00

i have a php script which creates a file if it not exists. the

  • 0

i have a php script which creates a file if it not exists. the php script sends the file after it created it. now i have the problem that my download class can’t download it (i don’t know exactly why) when the php file is creating a new file. but if the php script sends a cached file the download works.
Is there any way to let the android wait until the php script is done executing?

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.net.URLConnection;

import org.json.JSONObject;

import android.os.AsyncTask;
import android.os.Environment;
import android.os.Looper;
import android.provider.ContactsContract.Directory;
import android.util.Log;

public class DownloadMP3 extends AsyncTask<String, Integer, String> {
    private OnTaskRunning listener;
    public DownloadMP3(OnTaskRunning listener){
        this.listener=listener;
    }

    @Override
    protected String doInBackground(String... url) {
        int count;
        try {
            Log.d("Info", "create file");
            Download down = new Download();
            JSONObject jObject = new JSONObject(down.JSON(conf.d + "convert.php?v=" + url[0]));
            Log.d("Info","json file: " + jObject.get("fle"));

            URL u = new URL(conf.d + "convert.php?v=" + jObject.get("fle"));
            Log.d("Info", "dl u");
            URLConnection conexion = u.openConnection();
            Log.d("Info", "dl op");
            conexion.connect();
            Log.d("Info", "dl co");
            File directory = new File(Environment.getExternalStorageDirectory() + "/Music/VBT Splash/");
            Log.d("Info", "dl di");
            if (!directory.exists() || !directory.isDirectory()){
                directory.mkdirs();
            }



            InputStream input = new BufferedInputStream(u.openStream());

            String filename = conexion.getHeaderField("Content-Disposition");

            String file = filename.substring(filename.indexOf("\"")+1, filename.lastIndexOf("\""));

            OutputStream output = new FileOutputStream(Environment.getExternalStorageDirectory() + "/Music/VBT Splash/" + file);

            int lenghtOfFile = conexion.getContentLength();
            byte data[] = new byte[4096];

            long total = 0;

            listener.onTaskStarted();
            while ((count = input.read(data)) != -1) {
                total += count;
                output.write(data, 0, count);
                publishProgress((int) (total * 100 / lenghtOfFile));
            }
            Log.d("Info", "dl done");
            listener.onTaskDone();
            output.flush();
            output.close();
            input.close();
        } catch (Exception e) {
        }
        return null;
    }

    protected void onProgressUpdate(Integer... progress) {
        listener.onTaskProgress(progress[0]);
    }

    protected void onPostExecute(int result) {

    }
}
  • 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-06-17T21:13:59+00:00Added an answer on June 17, 2026 at 9:13 pm

    You must convey a re-direct to your client code. If you just hit the full file path url , and it doesn’t exists, it won’t be downloaded. So instead, first get download url from script. ( a new one will be created if it doesn’t exists) then, download that url. That makes a total of 2 requests to server.

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

Sidebar

Related Questions

I have a PHP script which creates and listens on a port for connections
I have a PHP-script originally developed on Ubuntu, which now has to run on
I have a php script that uploads a zip file of images to a
I have a PHP script which changes file permissions on my server using chmod.
I have a php script that does some processing (creates remittance advice PDFs, self-billing
I have this PHP script which i'm grabbing images from a directory and displaying
I have a php script which saves the original image, then resizes it -
I have a PHP script which is generating buttons to each content schedule. The
I have a PHP search script which I've altered slightly and works well for
Here I have a simple php script which displays some values from a database

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.