2012-10-20 132 views
-2

我有一個網頁在我的網站test.php的。而test.php的內容如下:PHP自動化測試後

<?php 
$testpostvalue=$_POST["testpostvalue"]; 
chmod("testpost.php", 0755); 
$my_file = "testpost.php"; 
$handle = fopen($my_file, "w") or die("Cannot open file: ".$my_file); 
fwrite($handle, $testpostvalue); 
chmod("testpost.php", 0644); 
?> 

我想從我的本地運行下面的代碼:

<? 
$testpostvalue=' 
<html> 
<title>test post</title> 
<head> 
<script src="http://code.jquery.com/jquery-latest.min.js"></script> 
</head> 
<center> 
<style> 
body{background-color:#000000;color:#000000;} 
</style> 
<img src="http://3.bp.blogspot.com/-2xHOAvaIImM/Ts-S6N8lSeI/AAAAAAAADDo/zBr0JfTVvSs/s320/image-708144.jpg"WIDTH="500" HEIGHT="500"</a> 
<center> 
<body>'; 


$useragent="Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322; Alexa Toolbar; .NET CLR 2.0.50727)"; 
$url2='http://mysite.com/test.php'; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url2); 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS,"testpostvalue=".$testpostvalue); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch, CURLOPT_HEADER, 0); 
curl_setopt($ch, CURLOPT_USERAGENT, $useragent); 
curl_setopt($ch, CURLOPT_COOKIEJAR, "COOKIE.txt"); 
curl_setopt($ch, CURLOPT_COOKIEFILE, "COOKIE.txt"); 
$buffer = curl_exec($ch); 

但是當我運行從我的本地後正在該代碼updated.But有一些問題與圖像link.The圖像鏈接出現這樣的test.php的:

<img src=/"http://3.bp.blogspot.com/-2xHOAvaIImM/Ts-S6N8lSeI/AAAAAAAADDo/zBr0JfTVvSs/s320/image-708144.jpg"WIDTH="500" HEIGHT="500"</a> 

回答

-1

你的代碼工作的文件,但我不建議您發送HTML文件,這樣的嘗試

curl_setopt($ch, CURLOPT_POSTFIELDS,"testpostvalue=". bin2hex($testpostvalue)); 

而且

fwrite($handle, pack("H*",$testpostvalue)); 
+0

可能工作,但不捲曲應該是安全的?你爲什麼會這樣建議?多一點學習是一個誠實的問題。 – PatomaS

+0

測試它,看到的是,由於您使用的是'CURLOPT_POSTFIELDS'。與二進制字符..輸出可能無法按預期 – Baba

+0

@ BABA 我用你的第一個advise.but輸出來 ????????? ?????????????????????????????????????????????????? ?????????????????????????????????????????????????? ?????????????????????????????????????????????????? ?????????????????????????????????????????????????? ?????????????????????????????????????????????????? ??????????????????????????????? d ????????? –

0

我會先嚐試清潔HTML代碼,因爲存在一定的誤差,特別是圍繞這個圖像檢查:

<html> 
<head> 
    <title>test post</title> 
    <script src="http://code.jquery.com/jquery-latest.min.js"></script> 
    <style> 
     body{background-color:#000000;color:#000000;} 
    </style> 
</head> 
<body> 
    <center> 
     <img src="http://3.bp.blogspot.com/-2xHOAvaIImM/Ts-S6N8lSeI/AAAAAAAADDo/zBr0JfTVvSs/s320/image-708144.jpg"WIDTH="500" HEIGHT="500" /> 
    <center> 
</body> 
</html> 
+0

與HTML part.canü沒有問題給出任何想法,使圖像鏈接正確顯示輸出頁面上? –