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
https://forums.phpfreaks.com/topic/196007-calling-files-by-id-stored-in-php-file/
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:

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.

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

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 ?

<?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..

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.