【发布时间】:2014-04-21 12:24:33
【问题描述】:
我这里有这个脚本,它可以将远程文件发送到我的服务器
问题是,如果我想重命名文件,我必须手动ftp到服务器并重命名文件。无论如何在下载之前命名文件吗?
<?php
if($_POST){
//get the url
$url = $_POST['url'];
//add time to the current filename
$name = basename($url);
list($txt, $ext) = explode(".", $name);
$name = $txt.time();
$name = $name.".".$ext;
//here is the actual code to get the file from the url and save it to the uploads folder
//get the file from the url using file_get_contents and put it into the folder using file_put_contents
$upload = file_put_contents("uploads/$name",file_get_contents($url));
//check success
if($upload) echo "Success: <a href='uploads/".$name."' target='_blank'>Check Uploaded</a>"; else "please check your folder permission";
}
?>
<html>
<head><title>File Upload from URL</title></head>
<body>
<h3>File Upload from URL</h3>
<form action="" method="post">
Your URL: <input type="text" name="url" />
</form>
</body>
</html>
谁能帮忙,我会很高兴的。
我必须手动重命名文件,这就是问题所在,无论如何我可以在上传之前指定一个名称吗?
提前致谢
【问题讨论】:
标签: php file file-upload upload