小编Roc*_*ket的帖子

PHP检查Filesize以查看它是否正在发生变化

我有一个调用外部进程的网页.此过程将文本文件写入我服务器上的文件夹.我无法控制这个外部过程.

我正在尝试监视文件以查看它的文件大小是否发生了变化,它会在写入时发生变化.一旦外部进程停止写入它,文件大小将保持不变.

我觉得这样的事情可能有用:

<?php

$old = 0;
$new = 1;

while ($old == $new) {
    $old = filesize ('/http/test/test.txt');
    echo $old;
    sleep(2);
    $new = filesize ('/http/test/test.txt');
    echo $new;
}
echo $old;
echo $new;
echo "done";
?>
Run Code Online (Sandbox Code Playgroud)

但事实并非如此.如何在文件停止增加之前暂停我的脚本?

这里有类似的问题,但我没有看到这样做的一个例子,没有使用flock()lsof两者我无法访问.

可以这样做吗?

谢谢

更新 这似乎是有效的.

<?php

$old = 0; $new = 1;
$filePath = "/http/test/test.txt";

while ($old != $new) {
    $old = filesize ($filePath);
    clearstatcache();
    sleep(1);
    $new = filesize ($filePath);
    clearstatcache();
}
echo "done";
?>
Run Code Online (Sandbox Code Playgroud)

php filesize while-loop

4
推荐指数
1
解决办法
1139
查看次数

BASH - 定时输入 - 显示倒计时

我有一个 bash 脚本,要求用户提供详细信息。

我正在设置等待输入的时间限制。我找到了这个,它看起来就是我想要的。

timelimit=5
echo -e " You have $timelimit seconds\n Enter your name quickly: \c"
name=""
read -t $timelimit name
#read -t $timelimit name <&1 
# for bash versions bellow 3.x
if [ ! -z "$name" ]
then
echo -e "\n Your name is $name"
else
echo -e "\n TIME OUT\n You failed to enter your name"
fi 
Run Code Online (Sandbox Code Playgroud)

它显示“你有 5 秒...”有什么方法可以更新输出,以便在倒计时时显示 4,3,2,1 等?

谢谢

bash input

3
推荐指数
1
解决办法
5650
查看次数

CSS突出显示列表条目

我创建了一个简单的列表如下:

.menu ul {
  font-size:20px;
  margin-left:0;
  list-style: none;
  padding-left:5px;

}

.menu li {
  position: relative;
  padding-left: 3em;
  margin: 0.45em 0;
  list-style: none;
  line-height: 1.8em;
  font-size:20px;
  cursor: pointer;
  -webkit-transition: all 0.2s ease-in-out;
  transition: all 0.2s ease-in-out;
}

.menu li:hover {
  color: #2693ff;
}

.menu li:after {
  position: absolute;
  top: 2.1em;
  left: 0.9em;
  width: 2px;
  height: calc(100% - 2em);
  content: '';
  z-index: 0;
}

.menu li li {
  font-size:20px;
}
Run Code Online (Sandbox Code Playgroud)
    <ul class="menu">
      <li class="menu"><span class="icon-indent"></span>Learn HTML</li>
      <li class="menu"><span class="icon-indent"></span>Create my own web …
Run Code Online (Sandbox Code Playgroud)

html css

2
推荐指数
1
解决办法
3519
查看次数

使用PHP动态生成表

我知道之前已经问过这个问题我使用以下代码了解它:

<?php
$maxcols = 8;  $i = 0;
echo "<table id='table1'><tr>";

foreach ($id as $k => $v) {
    echo "<td id='0'><div id='{$k}' class='drag t1'>{$v}</div></td>"; $i++;
    if ($i == $maxcols) { $i = 0; echo "</tr><tr>"; }
} $i++;


while ($i <= $maxcols) {
    $i++; echo "<td></td>";
}

echo "</tr></table>";
?>
Run Code Online (Sandbox Code Playgroud)

这会产生一个如下所示的表:

在此输入图像描述

我想为此添加标题,因此最终结果如下所示:

在此输入图像描述

我想动态地这样做,所以如果我创建一个只有5列宽的表,我会得到第一个标题行ID01 - ID05和第二个标题行ID06 - ID10

我想限制标头ID值不超过$ maxid任何额外的标头字段应该是空白的,如下所示:如果$ maxid = 12; 然后 :

在此输入图像描述

我需要标题行如下所示,而不是使用 <TH>

<td class="mark">
Run Code Online (Sandbox Code Playgroud)

我正在使用一些javascript来允许移动单元格数据.

该类用于设置标题上的格式,并阻止项目被拖入字段.

任何人都可以指出我如何做到这一点的正确方向.

php formatting html-table

1
推荐指数
1
解决办法
2万
查看次数

C++错误:无法将'std :: basic_string <char>'转换为'const char*'

我正在使用一个函数来下载文件.

void downloadFile(const char* url, const char* fname) {
  //..
}
Run Code Online (Sandbox Code Playgroud)

这被称为:

downloadFile("http://servera.com/file.txt", "/user/tmp/file.txt");
Run Code Online (Sandbox Code Playgroud)

这工作正常.

但我想将URL更改为数组中的值.该数组存储加密值,当解密时是字符串,所以我得到了问题error: cannot convert ‘std::basic_string<char>’ to ‘const char*’

我试过了:

 string test = decode(foo[5]);
 const char* t1= test.c_str();
 downloadFile(t1 "filename.txt", "/user/tmp/file.txt");

downloadFile(t1 + "filename.txt", "/user/tmp/file.txt");
Run Code Online (Sandbox Code Playgroud)

downloadFile((decode(foo[5]).c_str()) + "filename.txt", "/user/tmp/file.txt");
Run Code Online (Sandbox Code Playgroud)

这使: error: invalid operands of types ‘const char*’ and ‘const char [17]’ to binary ‘operator+’

我究竟做错了什么 ?

谢谢

c++ string string-concatenation

1
推荐指数
1
解决办法
6122
查看次数

PHP Order array by multiple elements - Date and Time based sorting

I have an array as follows:

$array = array (
    array(  'Day' => 'Monday',
            'Start' => '0830',
            'End' => '1730'),

    array(  'Day' => 'Monday',
            'Start' =>'1730',
            'End' => '2130'),

    array(  'Day' => 'Tuesday',
            'Start' => '0600',
            'End' => '1100'),

    array(  'Day' => 'Tuesday',
            'Start' => '0600',
            'End' => '0900'),           
);
Run Code Online (Sandbox Code Playgroud)

I'm trying to work out how to sort this so the results are sorted first by Day and then by the earliest Start, then End.

Using the above array, the …

php sorting date multidimensional-array

0
推荐指数
1
解决办法
39
查看次数

PHP 使用代码作为函数,变量不起作用

我有这个代码可以很好地独立运行:

file_put_contents('dataFile', implode('', 
    array_map(function($data) {
    return stristr($data,"NSQ = ") ? "NSQ = school\n" : $data;
    }, file('dateFile'))
));
Run Code Online (Sandbox Code Playgroud)

这会读取 dataFile 并找到条目NSQ =并将其更新为NSQ = school

我要多次重用这个,所以把它改成了一个函数:

function updatesite($site) {
file_put_contents('dataFile', implode('', 
    array_map(function($data) {
    return stristr($data,"$site = ") ? "$site = school\n" : $data;
    }, file('dateFile'))
));
}
Run Code Online (Sandbox Code Playgroud)

最初,我得到了一个$site不存在的错误,所以我global $site;在返回之前添加了。

这停止了​​错误,但它不会更新文件。

有什么办法可以使用这样的变量吗?

php function

0
推荐指数
1
解决办法
28
查看次数