PHP远程下载小脚本 CURL

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">         
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-cn">        
<head>        
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />        
<meta http-equiv="Content-Language" content="UTF-8" />        
<title>简单的CURL脚本</title>
</head>        
<form method="post">        
<h3>远程下载</h3>
<input name="url" size="20" />        
<input name="submit" type="submit" />        
<!-- <input type="hidden" name="MAX_FILE_SIZE" value="2097152" />-->        
</form>        
<?php
    set_time_limit(24*60*60);
    if (isset($_POST['submit'])){
	    $destination_folder = './';   // 文件夹保存下载文件。必须以斜杠结尾
	    $url = $_POST['url'];
	    $newfname = $destination_folder.basename($url);
	    $file = fopen($url, "rb");
	    if ($file) {
	        $newf = fopen($newfname, "wb");
	        if ($newf) while (!feof($file)) {
	            fwrite($newf, fread($file, 1024*8), 1024*8);
	        }
	    }
	    if ($file) {
	        fclose($file);
	    }
	    if ($newf) {
	        fclose($newf);
	    }
    }
    
	if (isset($_GET['del'])){
		unlink($_GET['del']);
    }
$dir = './';
$okfiletypes = array('php','html');

$files = array();
if (is_dir($dir)) {
	if ($dh = opendir($dir)) {
		while (($file = readdir($dh)) !== false) {
			if($file[0]=='.') continue;
			if($file=='index.php') continue;
			if (($file != '.') && ($file != '..')) $files[] = $file;
		}
		closedir($dh);
	}
}
sort($files);

foreach ($files as $file) {
	echo '<div><a href="'.$file.'">'.$file.'</a> <a href="?del='.$file.'">删除</a></div>';
}


    
?>

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

Back to Top