有人可以帮助这个脚本吗?
我正在寻找通过 url 上传到我的服务器。
我看到了很多选择,但没有一个不适合我。
这就是我想要做的
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<script type="text/javascript">
//Alerts to errors.
window.onerror=function(msg, url, linenumber){var logerror='Error message: ' + msg + '. Url: ' + url + 'Line Number: ' + linenumber;alert(logerror);return false}
</script>
<title>Upload Form</title>
<style type="text/css">
body
{
margin: 0 auto;
width:900px;
font-family:serif
}
#upload_box
{
background-color: LightBlue;
border:1px solid Black;
padding:20px;
margin-top:40px;
width: 50%;
}
</style>
<?php
if (isset($_POST['myupload']))
{
define('BUFSIZ', 4095);
$url = $_POST['upload'];
echo 'Trying with fread() ';
$target = 'up/';
$nname = basename($url);
$info = pathinfo($url);
var_dump($info);
$parse = parse_url($url);
echo '<br/><br/>';
if(isset($_POST['nname'])){
$nname = $_POST['nname'];
}
if(fopen($url, 'rb')){
$rfile = fopen($url, 'rb');
$lfile = fopen($target.$nname, 'wb');
while(!feof($rfile)){
fwrite($lfile, fread($rfile, BUFSIZ), BUFSIZ);
fclose($rfile);
fclose($lfile);
}
}else{
echo "Can't read from this directory";
}
$fp = fsockopen($parse['host'], 80, $errno, $errstr, 300);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "GET / HTTP/1.1\r\n";
$out .= "Host: ".$url."\r\n";
$out .= "User-Agent: Mozilla/5.0 Firefox/3.6.12\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, BUFSIZ);
}
fclose($fp);
}
}
?>
</head>
<body>
<div id="upload_box">
<form action="" method="post">
<input type="text" name="upload"><label>URL</label><br/>
<input type="text" name="nname"><label>NEW Name</label><br/>
<input type="submit" name="myupload" value="Upload File">
</form>
</div>
</body>
</html>
结果是:
Warning: fopen(http://xxx.co.uk/xxxx/xxxx.mp3): failed to open stream: Permission denied in
而对于 fsockopen 是同样的问题
Warning: fsockopen(): unable to connect to xxx.co.uk:80 (Permission denied) in xxx/index.php on line 53
Permission denied (13)