我有一个脚本,使用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>
现在我想得到服务器响应并在脚本中使用它,但第一个问题是我无法真正检查文件是否已上传,因为服务器通常找不到我上传的文件(但该文件几乎每次上传成功并在服务器上找到,所以让我们说上传工作)。第二件事是cURL的输出是空的。
我是在PHP中使用cURL的新手,所有这些对我来说都有些混乱,有人能指出我的正确方法吗?