dongou2019 2012-09-21 16:18
浏览 15

将上传文件脚本转换为上传网址

i have upload script which does the job for uploading in usual way like browse the file from computer and upload but i want to convert the existing script to upload from url.for example if i paste the url which is direct link of video file it should be uploaded to my server. i can use php copy method and feof to do the job but i want to do with my existing script as several other data are related to my uploading script i tried with above both method but its not working.

converting this code to accept remote url upload

 <form enctype="multipart/form-data" id="form1" method="post" action="">

    <p><label>Upload videos</label>     
    <input type="file" name="video">
            <span>Only mp4 is accepted</span>   
                    <input type="submit" value="Submit" class="button"></p>
 if (!eregi(".mp4$",$_FILES['video']['name'])) {

                 die("Unavailable mp4 format");
    }

    $uri = save_file($_FILES['video'],array('mp4'));        

    function save_file($file) {
 $allowed_ext = array('mp4');



 $ext = $file['name'];

if (in_array($ext, $allowed_ext)) {
die('Sorry, the file type is incorrect:'.$file['name']);
}
$fname = date("H_i",time()).'_'.get_rand(3);
$dir = date("Ym",time());
$folder = 'uploads/userfiles/'.$dir;
 $uri = $folder.'/'.$fname.'.'.$ext;
if (!is_dir($folder))
mkdir($folder, 0777);
if (copy($file['tmp_name'],$uri))
return $uri;
else {
return false;}}
?>
  • 写回答

2条回答 默认 最新

  • duanleiming2014 2012-09-21 16:21
    关注

    If you're getting a URL, you aren't getting a file upload so you can't just use a file upload script and wish it would work. Just use the copy() function to get the file from the URL and save it to your server.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度