/    Sign up×
Community /Pin to ProfileBookmark

Return linked file name without visiting it.

Hello,

I don’t know if PHP is the best server-side solution to do this with, but if something else would be better I’ll gladly move the thread elsewhere.

I have a URL with multiple query strings that returns a WAV file. I personally know the name of the file because I can read it once it downloads obviously, but it’s always a different file name and I need to be able to return the file name without visiting the URL, therefore forcing a download of the WAV file.

I figured having the server visit the URL, fetching the file name, and returning it to the user would be the easiest (only?) way to go.

Any help wold be appreciated. Thank you!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogFeb 16.2009 — If I'm understanding the question correctly, you could access the URL with the cURL functions and just grab the response headers, then parse them to get the file name, something like:
[code=php]
<?php
$url = "http://whatever";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
// Use preg_match() or such to parse $result for the filename
?>
[/code]
Copy linkTweet thisAlerts:
@juststrandedauthorFeb 16.2009 — Thanks. That will definitely work. Just what I needed.

Now I realize I have another problem. The URL is https secure. Only accessible when logged in, so the server needs to be logged in. How can I log my server into the account so it can access the file?
×

Success!

Help @juststranded spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...