duandao1931 2015-05-24 20:15
浏览 20

如何制作动态下载页面PHP?

I'm struggling to a problem. I've got a little upload script which is working fine! But I want to make anything similar like the modern download and upload websites. (FRee and Premium Downloads)

My situation right now is the following;

I can pass through a GET variable (file) which contains the filename.. Than the link which the user is getting to redirected to is; localhost:8888/uploads/download.php?file=filename.zip

But what I want to have, is that there is a link similar like; localhost/uploads/file/2d618s which does not contain the filename.

So what my question is; How can I make a link similar like; localhost/uploads/file/dsa827 <- Unique name per file instead of localhost/uploads/download.php?file=filename.zip

Below you can see the script which makes a link;

protected function get_download_url($file_name, $version = null, $direct = false) {
        if (!$direct && $this->options['download_via_php']) {
            $url = $this->options['script_url']
                .$this->get_query_separator($this->options['script_url'])
                .$this->get_singular_param_name()
                .'='.rawurlencode($file_name);
            if ($version) {
                $url .= '&version='.rawurlencode($version);
            }
            return $url.'&download=1';
        } 

How my download template is looking like;

<p class="name">
            <form name='download' id='downloadForm' method='POST' action=''>
                {% if (file.url) { %}<p>{%=file.name%}</p>
                    <a href="download.php?file={%=file.name%}" title="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%} name="{%=file.name%}" onclick="document.forms['download'].submit();">Download</a>
                {% } else { %}
                    <span>{%=file.name%}</span>
                {% } %}
            </p>
            </form>

You can also point it out as a shortlink link which many modern upload websites does have... (uploaded.net/file/daj18si -> ul.to/daj18si)

similar like that :)

Thanks in advance!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
    • ¥15 帮我写一个c++工程
    • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
    • ¥15 关于smbclient 库的使用