I've made a download page for my friends website.
The download is selected from the $_GET
But there are multiple uses of the page, such as;
downloads of .rars and .zips,
and viewable videos etc.
I would like to know if there's a way i can check what is passed from the $_GET['id']
To show whether it is a .rar or .flv, for example, so appropriate action can be taken to embed the .flv file instead of it showing a download link to the .flv
Example of urls -
www.mahcuz.com/wltg.php?id=somefile.rar
-
www.mahcuz.com/wltg.php?id=somefile.flv
-
Sorry if i'm not precise enough, i can elaborate more if needed.
thanks a bunch :D
7 11613
Markus,
You want to use the strpos() function. If the specified string (needle) is in your "id" variable (haystack) it will return an integer of the starting position - if not, it will return a "false" value... so something like:
[php]
if(strpos(".flv", strtolower($_GET['id'])) != false){
echo "This is an FLV File!!";
}else{
echo "This is NOT an FLV file!!";
}
[/php]Note, you'll also want to use strtolower to make sure that capitalized file extnesions (.FLV) get included as well.
Markus,
You want to use the strpos() function. If the specified string (needle) is in your "id" variable (haystack) it will return an integer of the starting position - if not, it will return a "false" value... so something like:
[php]
if(strpos(".flv", strtolower($_GET['id'])) != false){
echo "This is an FLV File!!";
}else{
echo "This is NOT an FLV file!!";
}
[/php]Note, you'll also want to use strtolower to make sure that capitalized file extnesions (.FLV) get included as well.
Ahh!
Thanks man :D
Or woman!
Cheers, again.
Ahh!
Thanks man :D
Or woman!
Cheers, again.
Haha - No problem - and I'm all man baby... yeah!
Mmmmm it doesn't work.
It only says that it's an flv file if flv (with no period before) comes immediately after the id=
?id=flv
returns true
?id=something.flv
or
?id=.flv
both return false..
I'm lost.
a better way to do this would be to use substr() which will take the last 4 chars into a new string. THis way, the file something.flv.exe won't be uploaded.
[PHP]
$substring = substr(strtolower($_GET['id'], -4));
if($substring == ".flv")
{
echo "This is an FLV File!!";
}
else echo "This is NOT an FLV file!!";
[/PHP]
Or even better, strrpos() would check from the end, so you could get the final extension using strrpos() and substr().
[php]if (($pos = strrpos($_GET['id'], '.')) != false) {
if ($pos < strlen($_GET['id'])) {
switch (strtolower(substr($_GET['id'], $pos + 1))) {
case 'flv':
echo "FLV";
break;
case 'zip':
echo "ZIP";
break;
}
}
}[/php]
Or even better, strrpos() would check from the end, so you could get the final extension using strrpos() and substr().
[php]if (($pos = strrpos($_GET['id'], '.')) != false) {
if ($pos < strlen($_GET['id'])) {
switch (strtolower(substr($_GET['id'], $pos + 1))) {
case 'flv':
echo "FLV";
break;
case 'zip':
echo "ZIP";
break;
}
}
}[/php]
Wait, I thought I just did that in 6 lines of code...
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Nel |
last post by:
Hi all,
Before I re-invent the wheel here, has anyone willing to share a basic
script to extract META keywords from a string. I have a string, let's say
$pageText that contains the dynamic...
|
by: Guy Robinson |
last post by:
I have the code below which parses an expression string and creates tokens.
Can anyone suggest the best of error checking for things like:
Valid variable only obj.attribute -whitespace allowed...
|
by: Tongu? Yumruk |
last post by:
I have a little proposal about type checking in python. I'll be glad
if you read and comment on it. Sorry for my bad english (I'm not a
native English speaker)
A Little Stricter Typing in Python...
|
by: Vish |
last post by:
Hello,
I am passing a string to a spell checking function which performs spell
check using word objects. It works fine but even though i have said
oWord.Visible = false;
the word application...
|
by: Sling |
last post by:
I code in Rexx on the mainframe which has 2 built-in functions: word(s,i) &
words(s).
word(s,i) returns the ith word in the s(tring), and words(s) returns the
number of words within the s(tring)....
|
by: bdog4 |
last post by:
I've got a spell checking function in php that will check the words in
a sentance and suggest corrections. Right now I have it to print out
the words with 6 suggestions for each misspelled word.
...
|
by: Jacek Dziedzic |
last post by:
Hi!
I need a routine like:
std::string nth_word(const std::string &s, unsigned int n) {
// return n-th word from the string, n is 0-based
// if 's' contains too few words, return ""
//...
|
by: OKB (not okblacke) |
last post by:
I'm trying to write a unicode raw string literal, and I seem to be
running up against a conflict between the \uXXXX unicode character
escape and the need to have a literal \u (i.e., backslash...
|
by: Brent |
last post by:
I have a list of company names (say, IBM, Corning, General Motors, and
another 5,000 of them).
If I take a body of text, a news article, for instance, and I want to
see which company names...
|
by: barcaroller |
last post by:
1. If I pass pointers (char*) as iterators to an STL algorithm and the
return value is an iterator, can I convert that iterator to a pointer? If
yes, how?
2. What is the internal...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |