Local Development and Remote Files

Recommended Posts


today I've tried the following:

Use .htaccess to rewrite the url conditionally if an image file was not found.
Rewrite target was$1

I guess that would work out great. Unfortunately Processwire checks to see if the file exists and outputs an error message in the Page Editor.
An option to disable this check would be great. (Similar to $config->debugIf = '::1'; or something)

It would be great being able to just use the live database locally without broken images all over the place.
I guess this might be a simple good enough solution for most use cases.

Share this post

Link to post
Share on other sites

I think this should work (not tested):

# Load media files from production server if they don't exist locally
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f [NC]
  RewriteRule ^(.*\.(js|css|png|jpe?g|gif|ico))$1 [NC,P,L]

...if this doesn't work for you, try php:

 * Load media files from production server if they don't exist locally
$wire->addHookAfter('Pagefile::url', function ($event) use($config) {
  $path = str_replace($config->urls->root, $config->paths->root, $event->return);

  if (!is_file($path)) {
    $event->return = str_replace($config->urls->root, '', $event->return);

Share this post

Link to post
Share on other sites

Hello Yannick Albert,

thank you for the suggestions. I'm sure these will work for the frontend.
Unfortunately i see the same results as with my other attempts.

The backend will just return error messages telling me that the files do not exist. (Screenshot)

Bildschirmfoto 2016-09-23 um 09.50.03.png

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 jmartsch
      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
      Basically this is based on my post here in the forums 
    • By louisstephens
      I have been looking up everything I can to try to find what's going wrong with this. I have a very simple form (title and file field set to multiple) that will create a new page with the name and attachments. However, it appears that I am missing something crucial as only 1 item gets uploaded to the field. Here is my code:
      <?php $uploadpage = new Page(); $uploadpage->template = "dashboard"; $uploadpage->parent = $pages->get("/testing/"); $uploadpage->title = $sanitizer->text($input->post->new_title); $uploadpage->save(); $uploadpage->setOutputFormatting(false); $u = new WireUpload('test_upload'); $u->setMaxFiles(6); $u->setOverwrite(false); $u->setDestinationPath($uploadpage->test_upload->path()); $u->setValidExtensions(array('jpg', 'jpeg', 'gif', 'png', 'pdf')); foreach($u->execute() as $filename) { $uploadpage->test_upload->add($filename); } $uploadpage->save(); ?> I have the max files set to 6, and have a foreach loop to add the files, but it is only uploading one. Does anyone see where I might have gone astray?
    • By hellomoto
      Pressing problem at initial posting:  I am working on a module that runs/previews (for pub/unpub) imports on importer page view. The template has to be in site/templates, so far as I know, so one is created there on install which includes a file to run from within the module, but then when it's run and tries to read the importer csv file it cannot, since it's in the admin, I guess... Is it possible to set the template page to a file in the module directory? Will that work?
    • By dragan
      In page-edit mode, it would be nice to have an optional download-button for inputfield type file.
      i.e. when a user has uploaded two dozen files (perhaps through the frontend), and someone else needs to download these from the backend all at once, without having to open an FTP client. There would simply be a download link / button, and a ZIP would be generated on the fly, containing all files.
      If someone has an idea how to do that (a hook?), I'd be all ears
    • By MedcomPanama
      Hi All!
      Currently Processwire saves the files in the assets directory as follows assets > files > pageid > jpg, doc, mp4, etc.
      But what happens I have a project that we developed 2 years ago and currently uses 2 TB of space because the majority of content is video, so I thought that if Processwire could save the files per year, it means that the structure is thus assets > files > year > Pageid > jpg, doc, mp4, etc.
      This in order to be able to create an NFS volume for each year and that the volume does not grow in an exaggerated way, since the bigger the volume, the longer the reading and writing times in that volume.