简体   繁体   English

如何使用php从文件夹中获取文件?

[英]how to get the file from a folder using php?

i have one folder,in that i have many files and i have four buttons also,the buttons are first,next,previous,last. 我有一个文件夹,因为我有很多文件,我也有四个按钮,这些按钮是第一,下一个,上一个,最后一个。 when i click on first button i want to get first file content and it should display which file currently working on.when i click on next button i want to get next file content,when i click on previous button want to get the previous file content,when i click on last button i want to get the last file content. 当我单击第一个按钮时,我想获取第一个文件内容,并且应该显示当前正在处理的文件。当我单击下一个按钮时,我想要获取下一个文件内容,当我单击上一个按钮时,想要获取上一个文件内容,当我单击最后一个按钮时,我想获取最后一个文件内容。

$next_slide=$text+"1";
echo $next_slide;
$a_str = array($_POST["content"]);
$contents = implode(PHP_EOL, $a_str);
$contents .= PHP_EOL . PHP_EOL;   
$get_content=file_get_contents($foldername.'/'.$next_slide."-html",$contents);

when i click on first getting first file content,passing the 1 as to php fie and adding +1 for get the next file content,but not get the second file content please help me how to do it? 当我单击第一个获取第一个文件内容时,将1传递给php fie,并添加+1以获取下一个文件内容,但不获取第二个文件内容,请帮助我该怎么做?

Try following and -html is not a valid extension 尝试关注以下内容,并且-html不是有效的扩展名

$handler = fopen($foldername.'/'.$next_slide.'.html','r');
$get_content = fread($handler);

You have to save customer choice: 您必须保存客户选择:

 $choice = 0;
 if(isset($_SESSION['actual'])){
     $choice = $_SESSION['actual']; or COOKIE as you want.
 }
 if($_GET['next']){
      $choice++;
 }
 elseif($_GET['previous']){
      $choice--;
 }
 elseif($_GET['first']){
      $choice = 'first';
 }
 elseif($_GET['last']){
      $choice = 'last';
 }
 $_SESSION['actual'] = $choice;

 $get_content=file_get_contents($foldername.'/'. $choice ."-html",$contents);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM