Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts

    Loading file name and file contents to variables from a URL

    Hey...

    Ok I don't know how 'do-a-ble' this is so tell me what ya think.. ill explain the basics...

    I need to find a free script.. or develop one myself (with some pointers from CF gods) that will go to a url.. one that I set it to go to...
    Once its there.. it needs to take the filename.. so after the last '/' in the url and before the .ext... and put that word(s) into a variable.. and then take whats in the file.. and put that into a variable.. so I can access them later on in the script.. once Ive got them i will be manipulating then dymanicly displaying those variables - the manipulating and displaying I can do fine.. its the going to the url and setting those 2 variables first of all...

    Is this gonna be amazinly complex? anyone have any points/links/ideas to help me?

    Thanks
    Sir P

  • #2
    New Coder
    Join Date
    Nov 2002
    Posts
    87
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Perhaps an example would help.

    I wonder what prevents the typical use of ?var=value url var style for this application.

    Also if you get files on your server based on url (or any user provided info) security issues must be taken into account.

    I use a switch statement and test my url vars for known good values.
    This allows me to safely ignore any hacked vars a user submits in an attempt to jump dirs or whatever else the current 'url hack of the day' is.

    I'm not saying your approach is wrong. I just would like to know more in order to be able to help.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    hey darknight,
    cheers for your reply.

    Well security isnt really an issue.. this is just a private feature that i plan on using - not used or even accessed by public visitors...

    I cant use root paths for this as I want to connect across my servers so i need to use http addresses...
    $var's in urls are fine.. i can use these.. just not to get the content of the file you know?

    I dont know how best to make an example but i will try and describe it again...
    if there is a text files at www.domain.com/files/foo.txt - i would enter that url into my script... i can do that.. just using a form, ill send it to let say $thisaddress ... now what the script needs to do is split up the file from the url.. so get the file name after the last /... so it should get foo.txt now i need it to remove the file extension so we are left with "foo" and set a variable.. lets say $name.. and set it as "foo"... and now grab everything within the file and put it in a variable called $content .. so all im left with is 2 variables .. $name and $content which would are holding foo and the file content.

    Does that make clearer sense? or did i ramble?

    Cheers, thanks for your time.
    Sir P

  • #4
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    You mean something like this...

    PHP Code:
    $url "http://mysite.com/path/to/my/file.ext";
    $file basename($url);
    list(
    $name$ext) = split(".",$file); 
    Then

    $file = "file.ext"
    $name= "file"
    and
    $ext = ".ext"

    Or am I not getting it???

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Hey bcarl314,

    yeh I spose that is the first part, the bit that sorts out the file name.. however when i run it and call $name or $ext nothing is returned?

    there are 2 parts tho, that part - which yeh u did understand... and pretty much sorted.. but theres also the matter of getting the contents of the file and putting that in a variable? anyway ideas bcarl314?

    Cheers
    Sir P

  • #6
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    Aha, I think I now understand....

    Try this...

    PHP Code:
    $fh fopen($url,"r");
    $d="";
    while(
    $data fgets($fh)) {
        
    $d.=$data;
    }
    fclose($fh); 
    All the file information will be in the $d var, just assign it to what ever var you want.

    PHP Code:
    $name $d
    Does that do the trick???

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    thats perfect bcarl314 thanks very much works great!

    still having problem with splitting the file from the file ext.. im calling it with $name which includes the ext.. i tried using $file.. but that brings back nothing.

    Any idea?
    Thanks

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    I starded at it for hours... i mean hours lol and ive sorted it now.. thanks everyone that helped!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •