Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取cURL服务器响应并在PHP中打印_Javascript_Php_Parsing_Curl - Fatal编程技术网

Javascript 获取cURL服务器响应并在PHP中打印

Javascript 获取cURL服务器响应并在PHP中打印,javascript,php,parsing,curl,Javascript,Php,Parsing,Curl,我有一个脚本,它使用PHP中的cURL将文件上传到服务器,我需要打印或保存响应以用于测试目的(最后,我将解析输出,但这不是我想说的) 我有以下代码: <?php include 'simple_html_dom.php'; $html = file_get_html('http://uloz.to/upload'); $form = $html->find('form[id=form_upload_nginx]', 0); $adress = $form->getAttrib

我有一个脚本,它使用PHP中的cURL将文件上传到服务器,我需要打印或保存响应以用于测试目的(最后,我将解析输出,但这不是我想说的)

我有以下代码:

<?php
include 'simple_html_dom.php';

$html = file_get_html('http://uloz.to/upload');
$form = $html->find('form[id=form_upload_nginx]', 0);
$adress = $form->getAttribute('action');

//echo 'Successfully parsed adress';
echo $adress;

$ch = curl_init();
$file = 'C:\some-file.jpg';
$data = array('upfile_0' => "@$file");

curl_setopt($ch, CURLOPT_URL, $adress);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$out = curl_exec($ch);
curl_close($ch);

echo '<p>';
echo strip_tags($out);
echo '</p>';
?>

服务器响应应如下所示:

<!DOCTYPE html>
<html>
    <head>
        <title>Redirect</title>
        <script>
            document.domain = document.domain.split('.').slice(-2).join('.');
            top.upload.onUploadCompleted('http://ulozto.net/done.php?rnd_id=419737883238269087&fileid=59286012&rt=&p_hash=&token=c603931da2fc2fba807accf205954e45');
        </script>
    </head>
    <body>
    </body>
</html>

重新使用
document.domain=document.domain.split('.').slice(-2).join('.');
top.upload.onUploadCompleted('http://ulozto.net/done.php?rnd_id=419737883238269087&fileid=59286012&rt=&p_hash=&token=c603931da2fc2fba807accf205954e45');
现在我想获得服务器响应并在脚本中使用它,但第一个问题是,我无法真正检查文件是否已上载,因为服务器通常无法找到我按名称上载的文件(但几乎每次都成功上载了文件并在服务器上找到了该文件,所以让我们假设上载工作正常)。第二件事是cURL的输出是空的


我是在PHP中使用cURL的新手,所有这些都让我有点困惑,有人能告诉我正确的方法吗?

你控制服务器吗?如果是这样,我们能看到处理上传的服务器代码吗?你说的“服务器通常找不到我按名字上传的文件”让我很困惑。服务器不需要“查找”任何内容。文件被传递到它。至于第二个问题,
$out
变量将包含来自服务器的响应。如果
$out
为空,则表示服务器未返回任何内容。更有可能的情况是,
$out
为FALSE,这意味着请求失败。使用
if($out==false){die(“上传失败”)}
检查情况是否如此。它是像Mega一样的公共文件存储,但您也可以搜索其内容。上载文件时,使用搜索访问此文件大约需要五分钟,这就是我无法实时查看结果的原因。但在服务器上使用搜索时,我发现上传本身是有效的(我上传了同一个文件,但文件名是唯一的,所以我可以看到哪些代码是有效的),可能只有cURL没有得到响应或者我做错了什么。我从命令行cURL获取了服务器响应,所以我99%确信它应该是这样的。@EvandelaCruz您可以看到表单本身并在www.uloz.to/upload上测试它