FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


File Functions not working with variables.





Dougie1
I don't fully know if I am doing this right but it is not working:
Code:
<?php
$video = @$_GET['video'];
$v = file("$video");
$st2 = "$v[232]";
echo $st2;
?>


Any help would be appreciated greatly Smile
hexkid
Dougie1 wrote:
I don't fully know if I am doing this right but it is not working:
Code:
<?php
$video = @$_GET['video'];
$v = file("$video");
$st2 = "$v[232]";
echo $st2;
?>


Any help would be appreciated greatly Smile

This script echo's the 233rd line of the file named according to the 'video' URL parameter.

If the file does not exist --> it will not work
If the file has less than 233 lines --> it will not work
If the 233rd line contains a single ENTER --> it will appear to not work

What exactly do you want to do?
Maxus
http://php.net/manual/en/function.file.php
sonam
If $video is not in same folder like your php script then path to file is not correct.


Sonam
Dougie1
Echoing anything from a url never works like this. I don't know why. It just doesn't seem to work. I have tried so much to get it to work.
hexkid
Code:
<?php
echo '<pre>'; print_r($_GET); echo '</pre>';
?>


[Edit]

Try the code above. Let's say you call it "get.php"

http://localhost/get.php?a=b&c=d&e=f
http://localhost/get.php?video=video.asx&format=asx&stop=yes
http://localhost/get.php?a&b&c
...
Dougie1
I tried the above and it works. On my file that I use I can also include this and it does echo the correct file (from get) but it does not want to open the file and do anything with it.

Any file I try to open and echo a line, or part of it, never works.
hexkid
Try this

Code:
<?php
$video = @$_GET['video'];

if (file_exists($video)) {
  if (is_file($video)) {
    if (is_readable($video)) {
      $v = file($video);        ## lose the quotes :) ==== file("$video")
      if (isset($v[232])) {
        $st2 = $v[232];         ## again  ==== "$v[232]"
        echo $st2;
      } else {
        echo "Error! '$video' does not have 233+ lines.\n";
      }
    } else {
      echo "Error! '$video' is not readable.\n";
    }
  } else {
    echo "Error! '$video' is not a file.\n";
  }
} else {
  echo "Error! '$video' does not exist.\n";
}
?>
Dougie1
With any url I get "Error! '.........' does not exist."

I just cannot seem to get a variable file that is a url to load. It is strange. Has anyone else managed to get one to load?
hexkid
It works for me.

I've put a version of my script above online at
http://www.hexkid.frih.net/video.php?video=video.php&line=11

In this version, the video parameter must be "video.php" and line works for values between 1 and 28.

The code is pretty much the same as above; if you want to know the full code just use different lines until you get it all Smile
Dougie1
That url is on your site. That seems to work fine because it is on your site. I can get files to load so long as they are on my site but on any other site they do not work. For examle:

http://www.hexkid.frih.net/video.php?video=http://www.youtube.com/watch?v=k2xG5n1Uf0s&line=210

I know you set that to only work with one file but you get the point.
hexkid
Dougie1 wrote:
I can get files to load so long as they are on my site but on any other site they do not work.

Two things:
1) Do you have allow_url_fopen enabled? (It is enabled on frihost.)
2) the functions file_exists(), is_file(), is_readable() do not work for URLs (except with PHP 5.0.0 or greater)

Dougie1 wrote:
For examle:

http://www.hexkid.frih.net/video.php?video=http://www.youtube.com/watch?v=k2xG5n1Uf0s&line=210

Well ... if you have PHP 5.0.0 or greater and allow_url_fopen enabled it should work ... but you should encode the video parameter

http://www.hexkid.frih.net/video.php?video=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dk2xG5n1Uf0s&line=210

[Are you sure you can download a video file like that?
Try first with a plain old HTML page.
hmmm ... never mind]
Related topics
20 Frih$
Cant Download File on my HOST
Gry mmorpg w przegladarce
phpBB question
An error in my forum
WHat is the best PHP guidebook?
.htaccess NOT WORKING
Server PHP file functions issues?
how do i create a Member access page
Limiting php file functions with .htaccess
Global Variable not working. Please test.
New endeavour: C programming language
.mpg file not working in Windows media player
Need a PHP expert or Wordpress wizard
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.