Jump to content

calling files by ID stored in php file.


ghaniz786

Recommended Posts

Hello

 

this is my first post. I am very new to php I have not done any course about scripting I want to know if I want to make a list of files like "list.php" and when i need to call a file i just put in HTML tag <a Href "list.php?id=5>File 5</a> so file should open.

 

Rather than call full file name I wnat to use that ids which was stored in a php file is it possible ? How to do this please help me.

 

Thanks

Link to comment
Share on other sites

Thanks For Reply

 

Yeah I am talk about thing like this but i need full script with example how to link (cal) this. can I call html file with this method ?

rather than page.html ?

and what if I want to open html in new window (_blank) ?

Please help because I have no idea  :shy:

Link to comment
Share on other sites

Ooops so have to use mysql database ? but I have no Idea to use that where can learn or get what I want ? any suggestions ? I am not feel shy to ask which I don't know Please someonw help me how create mysql database for files which I want to call by IDs is there any complete example ?.

 

Though someone will laugh on my stupidity but what I don't know I have to ask to seniors.

Link to comment
Share on other sites

list.txt

file1.txt
file2.html
file3.php
file4.mp3

 

list.php?id=x

$array=array();
$files=("./files.txt");
$i=1;
foreach($files as $file)
{
$file=trim($file);
$array[$i]=$file;
$i++;
}

$id = $_GET['id'];
$fn= $array[$id]';

 

usage

$link= "<a href=\"./$fn\">$fn</a>"
include("./$fn");
$files_array=file("./$fn");
$file_string=file_get_contents("./$fn");

 

 

HTH

Teamatomic

Link to comment
Share on other sites

Thanks for your reply although this example is too hard to understand for me coz I have no idea about php By this Example as far as I understand wwe have to make file list.txt file with the file name with extention then use script php but I could not understand what is the reason of loop ?

Link to comment
Share on other sites

<?php

$page = $_GET['id'];

if ($page == "1") { header('Location: http://www.your_url.com/page1.html'); }
if ($page == "2") { header('Location: http://www.your_url.com/page2.html'); }
if ($page == "3") { header('Location: http://www.your_url.com/page3.html'); }
?>

 

etc..

Link to comment
Share on other sites

It would be something like this...

<a href="http://your_url_here/name_of_file.php?id=1">click here for file 1</a>

 

or

 

 

<a href="http://your_url_here/name_of_file.php?id=2">click here for file 2</a>

 

etc.. If you need any more help dont hesitate to ask.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.