Search…

X3 Photo Gallery Support Forums

Search…
 
littlelio
Experienced
Topic Author
Posts: 25
Joined: 20 Nov 2018, 21:21

possible to automate FTP loading image at backend?

14 Jan 2019, 05:18

I tried to search the keyword FTP but too many results... so I have to start a topic.

Basically I need to automate the image uploading process. I just want to setup a watch folder on my pc, and copy images in, then it can be automatically uploaded to the website. Currently the upload interface is great, but it still needs human interaction.

On the pc side, I may need to figure how to write a script to watch and upload to an FTP address with login/password, but on the X3 side, is it can be done now? i.e. just throw the images into an FTP folder and it will process?

I saw in a thread that the 'save' button needed to be pressed... can we do better?
 
User avatar
mjau-mjau
X3 Wizard
Posts: 13997
Joined: 30 Sep 2006, 03:37

Re: possible to automate FTP loading image at backend?

15 Jan 2019, 00:10

littlelio wrote:On the pc side, I may need to figure how to write a script to watch and upload to an FTP address with login/password, but on the X3 side, is it can be done now? i.e. just throw the images into an FTP folder and it will process?
Yes, you can already do this. Images and folders.
littlelio wrote:I saw in a thread that the 'save' button needed to be pressed... can we do better?
That is correct, and let me briefly explain why: X3 uses a page CACHE system (for fast page output), which is based on "change". Once anything changes in your content (images, folders, settings), X3 pages need to be re-created to reflect new content. The X3 panel will always know when you make any "change", but when uploading by FTP, X3 cannot detect "change". This could result in stale (cached) pages being served, even after you upload new images by FTP.

The notification of "change" in X3 is pretty simple: X3 will "touch" the main /content/ directory when any changes are made from the panel. The DATE of the content directory is then used by X3 to validate the current cache.

Solution
Essentially, you must simply notify X3 that changes were made by touching the /content/ directory. I assume you are aware of the linux "touch" command (also available on Mac and in PHP), which simply updates the date-modified attribute of a directory. Three suggestions:
  1. Simply call "touch content" from your script. Pretty sure this should be possible somehow.
  2. Or create a file refresh.php with one line <?php touch('./content') ?>. You would somehow need to process that URL after changes were made.
  3. Or create a file config/touch.txt. After update, write a random string to this file, or simply update it in some way or other.
 
littlelio
Experienced
Topic Author
Posts: 25
Joined: 20 Nov 2018, 21:21

Re: possible to automate FTP loading image at backend?

16 Jan 2019, 02:27

Thanks Majau!

Is there any more details information source I could check about how to upload the images to FTP? Or just throw folder and images into content folder?

So we need a trigger such as touch command to the content folder... I am wondering what is my best way to upload the images to the server... in Windows, I used to write a power shell script, to use command to upload a new file to FTP. It is quite basic method but it works... maybe adding touch command after them?

Or some software may help. The main thing I need is to monitor a folder (assuming I use windows), if a new image comes, process it, then upload, then, add touch command in the end. In Linux this may be more straightforward.
 
User avatar
mjau-mjau
X3 Wizard
Posts: 13997
Joined: 30 Sep 2006, 03:37

Re: possible to automate FTP loading image at backend?

16 Jan 2019, 03:19

littlelio wrote:Is there any more details information source I could check about how to upload the images to FTP? Or just throw folder and images into content folder?
It's quite logical, and you can pretty much just drop folders and images into the content folder. Your X3 website's page/menu structure will simply be a reflection of the folders within content directory.

If uploading directly by FTP, you should consider your image resizing strategy (since the X3 panel cannot resize for you on upload). It would be counter-productive to upload 5 megapixel images at 5MB, since that is not web-friendly, and depending on server memory allocation, X3 might have problems resizing to preview sizes. It would be best if you transferred images anywhere from 1280 px to 2400 px (long size), as that is within "web friendly" parameters.
littlelio wrote:So we need a trigger such as touch command to the content folder... I am wondering what is my best way to upload the images to the server... in Windows, I used to write a power shell script, to use command to upload a new file to FTP. It is quite basic method but it works... maybe adding touch command after them?

Or some software may help. The main thing I need is to monitor a folder (assuming I use windows), if a new image comes, process it, then upload, then, add touch command in the end. In Linux this may be more straightforward.
Not sure I can offer any more advice. For uploading (synching) new images/folders, ANY process will do as long as the images/folders arrive within the X3 content directory. FTP, SSH or some "synch" application that synchs between local=>server.

As for the touch command, yes you would need to incorporate it into your workflow somehow. I am not familiar with power shell script, but surely it would have some command or other that can touch a file/dir and modify the date? Or upload a file /config/touch.txt with random content?