Jump to content
Eunico Cornelius

Downloading from php href

Recommended Posts

58 minutes ago, flydev said:

Hi,

check the doc :

 

Your link markup should be something like that :


<a href="{$page->myfilesfield->first->url}" download>download</a>

 

A tutorial :

 

I've seen this tutorial. However, I am trying to download the file by only using href="" and not tweaking _init.php. Let's say for example the file I have uploaded to the page is called sample.pdf . what would be the href parameter to download the file from the page?  

 

I tried this 

foreach ($page->files as $file) { 
        
        echo "<a href='{$page->files->url}' download>download {$file->name}</a><br>"; 
        
    }

but it gives me a 403 error.

Sorry I am new to this kind of thing.

Help anyone?

Share this post


Link to post
Share on other sites

Here is the answer I've been searching for

<?php 
    foreach ($page->files as $file) { 
        
        echo "<a href='{$file->url}' download>download {$file->name}</a><br>"; 
        
    }
?>

Thank you for the help :)

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Jens Martsch - dotnetic
      Hi folks, I published a new tutorial today which explains how to make a simple download function with ProcessWire (tested with version 3.0+). You find the tutorial on my website https://jensmartsch.de/blog/simple-file-downloads-with-processwire/
      Basically this is based on my post here in the forums 
       
    • By didhavn
      Hey everbody.

      I wanted to share something I have been working for quite some time, in total currently three premium Templates or Site-Profiles for ProcessWire 3 including a onepage template, a blog template and a blog+sidebar template.
       
      Here are some Quick Facts:
      Fully responsive Multilanguage support Full SEO support Optional Google Analytics Easily create new pages out of multiple predefined sections Lazyload the sections of a page [Group and update website-information into blogs] (blog, blog+sidebar) [Use tags to tag and group blog entries] (blog, blog+sidebar) [User-comments] (blog, blog+sidebar) [Create each page with or without sidebar] (blog+sidebar) Website-wide search by text or tags Password protect each page individually with sophisticated page-encryption with dummy texts and pixelated images
      Just go to https://pwtemplates.de to test the demos (e.g. blog-sidebar) and purchase them for a small expense allowance.
       

      Hope you like it!
    • By Harmen
      Hi folks,
       
      On the website I am working on I do have a form which needs to be filled in (duh) and when the user clicks on download, the data is send with ajax and processed in the same file by using the ProcessWire API with $config->ajax;
      The data which is provided by the user will be checked with data in my database. If the data is correct I want to push a file download. But this is not working at the moment. It seems like the content of the (.exe) file is pasted in the console instead of pushing the file. My code looks like this:
      if ($config->ajax){ $serial = $input->post('serial'); $DB = DB(); $query = $DB->prepare("/*My query here*/"); $query->bindParam("comparision", $serial, PDO::PARAM_STR); $query->execute(); $reply = ''; $SN_rows = $query->rowCount(); if (!$SN_rows > 0) { $reply = 'error'; } else { $reply = 'success'; $installer = $page->attachments->eq(1); $filename = "Filename"; $filepath = $installer->filename; $options = array( 'forceDownload' => true, 'exit' => true, 'downloadFilename' => $filename ); wireSendFile($filepath, $options); } echo $reply; exit(); } What am I doing wrong here or is it a bug? Is there another way to do this with the processwire API?
       
      Thanks in advance,
       
      ~Harmen
    • By Harmen
      On my website, my boss wants to put a catalog file. That isn't the problem. But since we are distributors, our customers want a catalog with their own logo. Is there any module or something like a module which can make that true? Maybe with a small in-file editor too? 
       
    • By hellomoto
      Attempting to download AdoptDefaultsFromParents (or any module) in PW3 admin produces the following slew of errors:
      The site/modules permissions = 755, allow_url_fopen & curl = on. How could this be? Why doesn't the download URL come through properly? I sorely miss the splendid convenience of this capability.
×
×
  • Create New...