PHP进度条不使用JQuery。 [英] PHP progress bar without using JQuery.

查看:79
本文介绍了PHP进度条不使用JQuery。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是php的新手,需要帮助。



我正在尝试根据我获得成功的内容搜索文件。

为此我在php中运行一个函数如下并显示结果表。



< ;  -  searchFileContents CLASS  - > 
<?php
#class 关键字搜索
< span class =code-keyword> class searchFileContents {
#变量的解释
var $ dir_name = ' '; // 要搜索的目录(root)
var $ search_phrase = ' '; // 要在文件中搜索的短语内容

var $ allowed_file_types = array(' txt'' htm'' html'); // 搜索的文件类型

var $ foundFiles ; // 将存储包含搜索词组的文件这里
var $ myfiles ; // 获取所有目录中的所有文件

#function使用输入参数搜索短语,例如
#directory name 要搜索的短语
函数搜索($ directory,$ search_phrase)
{
$ this-> dir_name = $ directory ; // 创建本地var目录
$ this-> search_phrase = $ search_phrase ; // 为短语创建本地变量

#get all文件 所有目录
$ rDirIter = new RecursiveDirectoryIterator($ this-> dir_name,FilesystemIterator :: SKIP_DOTS);
$ this-> myfiles = new RecursiveIteratorIterator($ rDirIter); // 使用php的递归方法获取所有文件

#array声明
$ this-> foundFiles = array();

// 如果搜索关键字/词组为空,则此代码将运行
if (空($ this-> search_phrase))die(' 请输入要搜索的内容!');

// 如果目录为空,则此代码将运行
if (空($ this-> dir_name))die(' 您必须选择要搜索的目录');

#搜索文件中的关键字
foreach ($ this-> myfiles as $ f // get $ f
{
#in_array()中的所有文件将检查如果 $ allowed_file_types 的扩展名为
#explode()将转换为路径到数组
#array_pop()会弹出数组末尾的元素,这里扩展名为
if (in_array(array_pop(explode) (' 。' $ f ) ),$ this-> allowed_file_types)) // 仅搜索允许的文件
{
$ contents = file_get_contents($ f); // 搜索文件中的关键字
if (stripos($ contents,$ this-> search_phrase)!== false)
$ this-> foundFiles [] = $ f ;
} // end of if
} // 结束日期
return $ this-> foundFiles;
} // 功能结束
} // 结束类searchFileContents
?>





我打电话给@



 <?php  
#搜索关键字
if($ _ POST ['' 提交'] == 提交
{ // 搜索请求显示我的搜索结果
$ SearchQuery = $ _POST [' txt_query']; #Search keyword
$ TestPath = C:/ intranet / www / Documnet_Search;
$ search = new searchFileContents;
$ search-> search($ TestPath,$ SearchQuery);

$ narray = array();
$ narray = $ search-> foundFiles; // 使用数组显示结果





现在我的搜索越来越大,因为添加了新文件现在需要时间。

有谁可以帮我实现进度条让用户知道搜索还在进行中?

解决方案

dir_name = ' '; // 要搜索的目录(根)
var


search_phrase = ' '; // 要在文件内容中搜索的短语

var

allowed_file_types = array(' txt'' htm'' html'); // 搜索的文件类型

var


Hi, I'm new to php and need help.

I'm trying to search files on the basis of their content in which I got success.
for that I'm running a function in php as follows and showing result table.

<!--searchFileContents CLASS-->
<?php
#class for keyword Search 
class searchFileContents{
	#Declarations of variables
    var $dir_name = '';//The directory to search (root)
    var $search_phrase = '';//The phrase to search in the file contents
	
    var $allowed_file_types = array('txt', 'htm', 'html');//The file types that are searched
    
    var $foundFiles;//Files that contain the search phrase will be stored here
    var $myfiles;// get all the files in all the directories
	    
	#function to search  the phrase with input parameters like 
	#directory name and the phrase to search
    function search($directory, $search_phrase)
	{
        $this->dir_name = $directory;//create a local var for directory
        $this->search_phrase = $search_phrase;// create a local var for phrase
        
		# get all the files in all the directories
		$rDirIter = new RecursiveDirectoryIterator($this->dir_name, FilesystemIterator::SKIP_DOTS);
		$this->myfiles = new RecursiveIteratorIterator ( $rDirIter);//get all the files using the recursive method of php 
		
		#array declaration
        $this->foundFiles = array();
        
		//if search keyword/phrase is empty this code will run
        if ( empty($this->search_phrase) ) die('Please type something to search!');
		
		//if directory is empty this code will run
        if ( empty($this->dir_name) ) die('You must select a directory to search');
        
		#Search the keyword inside the files
        foreach ( $this->myfiles as $f )//get all the files in $f
		{
			#in_array() will check if $allowed_file_types has the extension or not
			#explode() will convert the path into array
			#array_pop() will Pop the element off the end of array, here extension of file
            if ( in_array(array_pop(explode ( '.', $f )),  $this->allowed_file_types) )// search the allowed files only
			{
                $contents = file_get_contents($f);//search the keyword inside the files
                if ( stripos($contents, $this->search_phrase) !== false )					
                    $this->foundFiles [] = $f;					
            }//end of if
        }//end of for
        return $this->foundFiles;
    }//end of function
}//end of class searchFileContents	
?>



which I'm calling @

<?php	
#Search the keyword 
if($_POST['Submit']=="Submit") 
{ //a search request was made display my search results 
	$SearchQuery = $_POST['txt_query']; #Search keyword 
	$TestPath="C:/intranet/www/Documnet_Search"; 	
	$search = new searchFileContents; 
	$search->search($TestPath, $SearchQuery); 
	
	$narray = array();
	$narray = $search->foundFiles;// use the array to show the result



Now my search is getting bigger as new files are added and now its taking time.
Could anyone please help me to implement a Progress bar to let the user know that the search in still in progress?

解决方案

dir_name = '';//The directory to search (root) var


search_phrase = '';//The phrase to search in the file contents var


allowed_file_types = array('txt', 'htm', 'html');//The file types that are searched var


这篇关于PHP进度条不使用JQuery。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆