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 8547325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:14:32+00:00 2026-06-11T13:14:32+00:00

I am using following codes to upload remote files to my server. It works

  • 0

I am using following codes to upload remote files to my server. It works great where direct download link is given but recently I have noticed that few websites are giving mysql links as download link and when we click on that link the files start downloading to my pc. But even in html source of that page it does not show the direct link.

Here is my code:

 <form method="post">
 <input name="url" size="50" />
 <input name="submit" type="submit" />
 </form>
 <?php
 if (!isset($_POST['submit'])) die();
 $destination_folder = 'mydownloads/';
 $url = $_POST['url'];
 $newfname = $destination_folder . basename($url);
 $file = fopen ($url, "rb");
 if ($file) {
 $newf = fopen ($newfname, "wb");

  if ($newf)
 while(!feof($file)) {
 fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 );
 }
 }

 if ($file) {
  fclose($file);
 }

if ($newf) {
fclose($newf);
}

?>

It works great for all links where the download link is direct for example if I will give
http://priceinindia.org/muzicpc/48.php?id=415508 link it will upload the music file but the file name will be 48.php?id=415508 but the actual mp3 file is stored at
http://lq.mzc.in/data48-2/37202/Appy_Budday_(Videshi)-Santokh_Singh(www.Mzc.in).mp3

So if I can get the actual destination url the name will be Appy_Budday_(Videshi)-Santokh_Singh(www.Mzc.in).mp3

So I want to get the actual download url.

  • 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-11T13:14:33+00:00Added an answer on June 11, 2026 at 1:14 pm

    The problem is the original URL is redirecting. You want to catch the URL it is being redirected to, try using the headers and then get the basename($redirect_url) as your file name.

    +1 for Robbie using CURL.

    If you run (from command line)

    [username@localhost ~]$ curl http://priceinindia.org/muzicpc/48.php?id=415508 -I
    HTTP/1.1 302 Moved Temporarily
    Server: nginx/1.0.10
    Date: Wed, 19 Sep 2012 07:31:18 GMT
    Content-Type: text/html
    Connection: keep-alive
    X-Powered-By: PHP/5.3.10
    Location: http://lq.mzc.in/data48-2/37202/Appy_Budday_(Videshi)-Santokh_Singh(www.Mzc.in).mp3
    

    You can see the location header here is the new url.

    in php try something like

    $ch = curl_init('http://priceinindia.org/muzicpc/48.php?id=415508'); 
    curl_setopt($ch, CURLOPT_HEADER, 1); // return header
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); // dont redirect 
    $c = curl_exec($ch); //execute
    echo curl_getinfo($ch, CURLINFO_HTTP_CODE); // will echo http code.  302 for temp move
    echo curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); // url being redirected to
    

    You want to find the location part of the header. not sure the setting im sure though.

    EDIT 3..or 4?
    Yeah right, I see whats happening. You actually want to follow the location url then echo the effective url without downloading file. try.

    $ch = curl_init('http://priceinindia.org/muzicpc/48.php?id=415508');
    curl_setopt($ch, CURLOPT_NOBODY, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    $c = curl_exec($ch); //execute
    echo curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); // url being redirected to
    

    When I run this my output is

    [username@localhost ~]$ php test.php
    [audio src="http://lq.mzc.in/data48-2/37202/Appy_Budday_(Videshi)-Santokh_Singh(www.Mzc.in).mp3" /]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following code to upload an image to a web server
When I upload files in Yii using the following code it generates an error.
I know that using the following codes will make each column have unique values,
I am using the following codes, to replace a JLabel each 0.5 seconds, with
i am using following code to display remote image with next and previous buttons.
I am using the following code to upload photo to facebook hconnect = WinHttpConnect(hsession,Lgraph.facebook.com,INTERNET_DEFAULT_HTTPS_PORT,0);`hrequest
I am using the following code to upload a video to Youtube through youtube
All, I'm using the following code to upload some images to my Wordpress blog:
I am trying to upload an image using django and following a tutorial from
I am using the following code but don't know why thumbnails are not created.

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.