我只是shell_exec在我的Linux服务器上试验PHP .这是一个非常酷的功能,到目前为止我真的很享受它.有没有办法查看命令运行时正在进行的实时输出?
例如,如果ping stackoverflow.com运行时,在ping目标地址时,每次ping时,都会用PHP显示结果?那可能吗?
我很乐意看到缓冲区正在运行时的实时更新.也许这不可能,但肯定会很好.
这是我正在尝试的代码,我尝试过的每一种方法总是在命令完成后显示结果.
<?php
$cmd = 'ping -c 10 127.0.0.1';
$output = shell_exec($cmd);
echo "<pre>$output</pre>";
?>
Run Code Online (Sandbox Code Playgroud)
我试过把这个echo部分放在一个循环中,但仍然没有运气.任何人都有任何建议让它显示屏幕上的实时输出而不是等到命令完成?
我试过exec,shell_exec,system,和passthru.它们中的每个人都在完成后显示内容.除非我使用了错误的语法或者我没有正确设置循环.
当从我的页面上的表单到我的服务器的POST数据时,我收到一个新的php警告.警告如下:
PHP警告:未知:输入变量超过1000.要在php.ini中增加限制更改max_input_vars.在第0行的Unknown中,引用者:https://mywebsite.com/index.php
问题是我的表单没有近1000个输入变量,所以我很困惑为什么会出现这个变量.作为旁注,我直到最近才遇到这个问题,我怀疑当我运行yum update更改/安装了导致此问题的内容时.任何建议或答案都表示赞赏.
编辑1:所以我做var_dump($_REQUEST)了〜1000个单字符串.数组中的前几个项目应该是它们应该是什么,但是我不需要提交的一些东西被分解为单个字符串.欢迎思考.
array(1001) {
["action"]=> string(10) "step1_show"
["submit"]=> string(6) "Step 1"
[0]=> string(1) "a"
[1]=> string(1) "c"
[2]=> string(1) "t"
[3]=> string(1) "i"
[4]=> string(1) "o"
[5]=> string(1) "n"
[6]=> string(1) "="
[7]=> string(1) "l"
[8]=> string(1) "o"
[9]=> string(1) "g"
[10]=> string(1) "o"
[11]=> string(1) "u"
[12]=> string(1) "t"
[13]=> string(1) "&"
[14]=> string(1) "p"
[15]=> string(1) "r"
[16]=> string(1) "o"
[17]=> string(1) "p"
[18]=> string(1) "e"
[19]=> string(1) …Run Code Online (Sandbox Code Playgroud) 如何测试以查看以下查询是否成功执行?
$STH = $this->_db->prepare("UPDATE UserCreds SET
VerificationString=:newVerificationString, ExpiryDate=:expiryDate
WHERE UserID = :userID;");
$STH->execute($params);
Run Code Online (Sandbox Code Playgroud)
我知道我可以lastInsertId()在添加新行时使用,但是UPDATE和SELECT呢?
使用jQuery,我们可以模拟提交表单:
<form id="form1" method="post">
<input name="key1" value="value1" />
<input name="key2" value="value2" />
</form>
Run Code Online (Sandbox Code Playgroud)
使用AJAX函数调用:
$.post('', { key1: 'value1', key2: 'value2' }, function() {
// do call back
});
Run Code Online (Sandbox Code Playgroud)
如果我们使用 jquery.form.js
$('#form1').ajaxSubmit({
success: function() {
// do call back
}
});
Run Code Online (Sandbox Code Playgroud)
我没有标记中的表单,我想使用"POST"方法提交包含一些动态内容的表单.
我想进行一个函数调用来模拟程序,可能是这样的:
utils.post('/url', {key1: 'value1', key2: 'value2'});
Run Code Online (Sandbox Code Playgroud)
在那次调用之后,效果与我上面的形式相同,我以自然的同步方式提交它.
有一个很好的方法来做到这一点?
如果问题不明确,我可以用一个丑陋的例子来解释我想要的东西:
util.post = function(url, fields) {
var $form = $('<form action="'+url+'" method="post"></form>');
var key, val;
for(key in fields) {
if(fields.hasOwnProperty(key)) {
val = fields[key];
$form.append('<input type="hidden" name="'+key+'" value="'+val+'" />');
} …Run Code Online (Sandbox Code Playgroud) 我希望能够通过一些变量发送到文件file_get_contents().
这是firstfile.php:
<?php
$myvar = 'This is a variable';
// need to send $myvar into secondfile.php
$mystr = file_get_contents('secondfile.php');
?>
Run Code Online (Sandbox Code Playgroud)
这是secondfile.php:
The value of myvar is: <?php echo $myvar; ?>
Run Code Online (Sandbox Code Playgroud)
我希望变量$mystr相等'The value of myvar is: This is a variable'
还有其他功能可以让你在PHP中执行此操作吗?
我目前收到以下错误:
"表单的视图数据应该是Symfony\Component\HttpFoundation\File\File类的实例,但是是一个(n)字符串.您可以通过将"data_class"选项设置为null或添加视图来避免此错误将(n)字符串转换为Symfony\Component\HttpFoundation\File\File的实例的转换器."
SoundController - 上传功能
/**
* @Security("is_granted('IS_AUTHENTICATED_FULLY')")
* @Route("/song/upload", name="upload_song")
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function uploadSong(Request $request)
{
$song = new Sound();
$form = $this->createForm(SoundType::class, $song);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid())
{
$file = $song->getFile();
$user = $this->getUser();
$fileName = $this
->get('app.file_uploader')
->setDir($this->get('kernel')->getRootDir()."/../web".$this->getParameter('songs_directory'))
->upload($file);
$song->setFile($fileName);
$file = $song->getCoverFile();
if ($file === null)
{
$song->setCoverFile($this->getParameter('default_cover'));
}
else
{
$fileName = $this
->get('app.file_uploader')
->setDir($this->get('kernel')->getRootDir()."/../web".$this->getParameter('covers_directory'))
->upload($file);
$song->setCoverFile($fileName);
}
$song->setUploader($user);
$song->setUploaderID($user->getId());
$user->addSong($song);
$entityManager = $this->getDoctrine()->getManager();
$entityManager->persist($song);
$entityManager->flush();
return …Run Code Online (Sandbox Code Playgroud) 我是MVC的新手,刚开始练习它.我正在创建一个中小型企业网站,并且不想使用任何大型框架,所以我发现了这个,到目前为止它工作得很好.我似乎唯一不理解的是如何在子文件夹中呈现视图.
我有3种药物需要显示信息,它们的结构如下:
views
--medicines
----medicine1
------info.php
------forms
--------male.php
--------female.php
Run Code Online (Sandbox Code Playgroud)
这是药物控制器:
<?php
class MedicinesController extends Controller
{
/**
* Construct this object by extending the basic Controller class
*/
public function __construct()
{
parent::__construct();
Auth::checkAuthentication();
}
/**
* Handles what happens when user moves to URL/medicines/index
**/
public function index()
{
$this->View->render('medicines/index');
}
/**
* Handles what happens when user moves to URL/medicines/medicine1
**/
public function medicine1()
{
$this->View->render('medicines/medicine/info', array(
'files' => FilesModel::getMedicineFiles())
);
}
/**
* Handles what …Run Code Online (Sandbox Code Playgroud) 使用PHP验证文件名的最佳方法是什么?我该怎么做?
我想看看文件名是否只包含"az","0-9"和" - ".还要确保文件名没有大写字母.
$file = 'the-name.ext';
if ($file == 'only contains a-z, 0-9 or "-"' // HOW TO
&& $file == 'lowercasse' // HOW TO
&& $file == 'a-z') // HOW TO
{
// upload code here
}
else{
echo 'The file "' . $file . '"was not uploaded. The file can only contain "a-z", "0-9" and "-". Allso the files must be lowercasse. ';
}
Run Code Online (Sandbox Code Playgroud)
我最终做了这样的事情,以摆脱文件扩展名:
$filename = 'fil-name.jpg';
$filname_without_ext = pathinfo($filename, PATHINFO_FILENAME);
if(preg_match('/^[a-z0-9-]+$/',$filname_without_ext)) {
echo'$file is valid'; …Run Code Online (Sandbox Code Playgroud) 你好,
我试着改写我的问题,因为我的最后一个问题并不是每个人都清楚的.
这是我的测试表
+----------+---------+-------+
| rel_id | genre | movie |
+----------+---------+-------+
| 1 | 1 | 3 |
| 2 | 8 | 3 |
| 3 | 3 | 3 |
| 4 | 2 | 5 |
| 5 | 8 | 5 |
| 6 | 3 | 5 |
| 7 | 1 | 8 |
| 8 | 8 | 8 |
| 9 | 3 | 8 |
| 10 | 5 …Run Code Online (Sandbox Code Playgroud) 我试图弄清楚如何将API网关中的Lambda响应映射到不同的状态代码,同时从我的Lambda函数接收JSON对象.
我在Lambda中有以下内容:
context.done('Not Found:',jsonObject);
Run Code Online (Sandbox Code Playgroud)
在我的API网关中,在集成响应中,我在403上有一个Lambda错误正则表达式,上面写着Not Found:.*.这样做,该方法返回一个返回403.
问题是我似乎无法返回jsonObject.我试图创建一个看起来像这样的应用程序/ json映射模板(也在集成响应下):
{"error" : $input.json('$')}
Run Code Online (Sandbox Code Playgroud)
但这只会导致我的回答看起来像这样:
{"error" : {"errorMessage":"Not Found:"}}
Run Code Online (Sandbox Code Playgroud)
我误解了映射模板吗?
php ×7
mysql ×2
ajax ×1
aws-lambda ×1
centos ×1
data-class ×1
file-upload ×1
filenames ×1
forms ×1
javascript ×1
jquery ×1
pdo ×1
sql ×1
sql-order-by ×1
symfony ×1
validation ×1
where-in ×1