jQuery File Upload - Image preview links

时间:2016-08-31 12:13:28

标签: javascript jquery-ui hyperlink jquery-file-upload

I'm using the jQuery File Upload. Everything works well during the upload process (files are getting uploaded well, in a folder I chose on my server).

But then, when images are uploaded, I should see them in a <a> in the <span class="preview"> that is generated by the <script id="template-download"> (original script from demo file).

In place, I get an broken link image and a "404 (not found)" in the console. Indeed when I check where It's looking for the image I have something like :

href="/home/domaindb/domain.fr/uploads/image.png"

Whereas it should be something like :

href="/uploads/image.png"

So, how can I change the way href links are created ? When I'm looking directly in the <script id="template-download"> on my upload page, there is the <a href="{%=file.url%}"> but I guess there's nothing to do here.

1 个答案:

答案 0 :(得分:0)

好的,最后我找到了解决方案。

在UploadHandler.php中,默认设置为'download_via_php' => false。我将其设置为'download_via_php' => 1以允许通过PHP通过readfile方法下载。

现在,href链接看起来像这样:

href="http://domain.fr/jquery-fu/server/php/index.php?file=IM1.png&download=1"

我认为这样更安全,因为它没有显示服务器上文件的真实路径(如果有人可以确认......)。