Search…

X3 Photo Gallery Support Forums

Search…
 
User avatar
gaitt
Experienced
Topic Author
Posts: 46
Joined: 21 Nov 2010, 12:48

Run script when done uploading

13 Jun 2011, 12:44

Hey guys,

I wondering if anyone can help me out!
I'd like to run an shell script when an uploading session is done.

For example, i put 10 pics to upload. When the last picture is succefully uploaded, the uploader start my shell script!
Is it something possible or not?

I know how to run a script from php but i don't know what file i should look into!

Thx,
Gautier
 
User avatar
Martin
Experienced
Posts: 651
Joined: 30 Jan 2011, 23:24

Re: Run script when done uploading

13 Jun 2011, 12:57

gaitt wrote:I'd like to run an shell script when an uploading session is done.
I'm really curious what you want the shell script to do after an uploading session....
 
User avatar
gaitt
Experienced
Topic Author
Posts: 46
Joined: 21 Nov 2010, 12:48

Re: Run script when done uploading

13 Jun 2011, 13:13

The thing is i'm not the only one who can upload files on my gallery, so i'd like to check that the uploaded pictures are in the good resolution (if not resize them) and also to do a sort of newsletter, send an email that say "new pictures are available".
:)
 
User avatar
Martin
Experienced
Posts: 651
Joined: 30 Jan 2011, 23:24

Re: Run script when done uploading

13 Jun 2011, 13:33

gaitt wrote:The thing is i'm not the only one who can upload files on my gallery, so i'd like to check that the uploaded pictures are in the good resolution (if not resize them) and also to do a sort of newsletter, send an email that say "new pictures are available".
:)
Ah... that explains a lot... such a situation didn't cross my mind...
Thanks for the insight... don't have a solution, I'm afraid... :)
 
User avatar
Nick
Imagevue Hitman
Posts: 2872
Joined: 02 May 2006, 09:13

Re: Run script when done uploading

14 Jun 2011, 06:25

Iv-includes/admin/controller/IndexControllers.php
Code
	/**
	 * Upload file
	 *
	 */
	function uploadAction()
	{
firedev.com
 
User avatar
gaitt
Experienced
Topic Author
Posts: 46
Joined: 21 Nov 2010, 12:48

Re: Run script when done uploading

14 Jun 2011, 17:14

Thanks Nick!!

I suppose it's "admin/controller/IndexControllers.php" coz "Iv-includes/admin/controller/IndexControllers.php" doesn't exist on my gallery!
Anyway, could you give me some help/tips to do it, i was thinking i can do it myself but i only know some newby stuff of php so ... and the functions i tried so far doesn't seems to be called.

If you plan to do some newsletter oriented features in the 2.8 release, then maybe i can wait! :D
 
User avatar
Nick
Imagevue Hitman
Posts: 2872
Joined: 02 May 2006, 09:13

Re: Run script when done uploading

15 Jun 2011, 00:54

Sorry iv-admin/controllers/IndexController.php (I assume you have the latest version of Imagevue)

Just add
Code
mail('to@me.com','New file uploaded',$imageName); 
after
Code
echo "File {$imageName} succesfully uploaded";
It should work. I think you can expand this code as you see fit.
firedev.com
 
User avatar
gaitt
Experienced
Topic Author
Posts: 46
Joined: 21 Nov 2010, 12:48

Re: Run script when done uploading

18 Jun 2011, 14:00

Well hmmm, it's not working!

If i run a php script from command line with "mail", everything works fine.
But in the IndexController, nothing happen when i upload files.

Even a simple
Code
touch('/var/www/toto');
just after
Code
echo "File {$imageName} succesfully uploaded";
doesn't work!
It's weird, i'm kind of lost rigth now.

How can i see the prints of "echo". Did i need a php debugger?
Thx in advance.
 
User avatar
Nick
Imagevue Hitman
Posts: 2872
Joined: 02 May 2006, 09:13

Re: Run script when done uploading

19 Jun 2011, 03:10

This is a callback function for JS, it doesn't really output anything you can see. Just checked my own code though:
Code
mail('nick@whatever',"File {$imageName} succesfully uploaded","File {$imageName} succesfully uploaded");
And here it is
Code
To: nick@whatever.local
Subject: File Page Capture 1.png succesfully uploaded
Date: Sun, 19 Jun 2011 14:09:05
From: pain@mini.local (Nick)

File Page Capture 1.png succesfully uploaded
So it should work. Are you sure you're not editing IndexController in iv-admin/guestControllers?
firedev.com
 
User avatar
gaitt
Experienced
Topic Author
Posts: 46
Joined: 21 Nov 2010, 12:48

Re: Run script when done uploading

26 Jun 2011, 17:38

Ok, i finally figured out what was wrong!!

I'm using msmtp for handling emails on my server. In php.ini the "sendmail_path" configuration was ok but the config file of msmtp wasn't own by www-data!

So, right now i receive 1 mail for 1 picture added! Is there any possiblility to get 1 mail for 1 upload session (for ex: 1 mail for 10 pictures added)??

BTW, thx very much Nick for helping!
 
User avatar
Nick
Imagevue Hitman
Posts: 2872
Joined: 02 May 2006, 09:13

Re: Run script when done uploading

28 Jun 2011, 09:53

Sorry but there is no place to hook up something like this in the code.
firedev.com
 
User avatar
Artur
Imagevue PowerPack
Posts: 510
Joined: 20 May 2011, 03:17

Re: Run script when done uploading

26 Aug 2011, 10:46

Hello.

I have noob question :oops: .

I put some code, just after:
Code
echo "File {$imageName} succesfully uploaded";
My code is:
Code
$dom = new DomDocument('1.0', 'UTF-8');
$element = $dom->createElement($imageName);
$dom->appendChild($element);
$dom->save("new_files.xml");
Why my code doesn't work? Even if something is in xml file, script rewrite it, and save as empty file.
When I write "some_text" instead of $imageName, then works fine, my xml file looks like:
Code
<?xml version="1.0" encoding="UTF-8"?>
<some_text />
 
User avatar
Nick
Imagevue Hitman
Posts: 2872
Joined: 02 May 2006, 09:13

Re: Run script when done uploading

29 Aug 2011, 07:22

I believe this is explained by the fact that $imageName doesn't have valid XML node name. It has dots in it. You can't have <image.jpg /> in XML.
firedev.com
 
User avatar
Artur
Imagevue PowerPack
Posts: 510
Joined: 20 May 2011, 03:17

Re: Run script when done uploading

29 Aug 2011, 11:22

Yes. I can see now, that $imageName is not only name of image, but also "dot" + extension.

Already done code that store the last 20(can be changed) images in the xml file. The rest job is done by the flash module :wink:
If somebody will need, there is the code I use (I know it can be simplified , but I'm not so good PHP coder):
Code
$simplepath = ROOT_DIR . $this->path;
$today = date("m.d.y"); 
$thumbPrefix = "tn_";
$swfAddressPrefix = "#";
$imageUrl = "$swfAddressPrefix$simplepath$imageName";
$thumbnailUrl = "$simplepath$thumbPrefix$imageName";

function loadXmlFile() {
	$domtree = new DOMDocument('1.0', 'UTF-8');
	$domtree->load("new_files.xml");
				
	$rootElement = $domtree->documentElement;
	$newImage = $domtree->createElement("image");
	$newImage = $rootElement->appendChild($newImage);
								
	$fileDetails = $domtree->createAttribute("date");
	$newImage->appendChild($fileDetails);
	$imageDetails = $domtree->createTextNode($today);
	$fileDetails->appendChild($imageDetails);
								
	$thumb = $domtree->createAttribute("thumb");
	$newImage->appendChild($thumb);
	$thumbValue = $domtree->createTextNode($thumbnailUrl);
	$thumb->appendChild($thumbValue);
								
	$imagelink = $domtree->createAttribute("image_link");
	$newImage->appendChild($imagelink);
	$imageValue = $domtree->createTextNode($fullpath);
	$imagelink->appendChild($imageValue);
								
	$imagename = $domtree->createAttribute("image_name");
	$newImage->appendChild($imagename);
	$imagenameValue = $domtree->createTextNode($imageName);
	$imagename->appendChild($imagenameValue);
							
	$itemsId = $domtree->getElementsByTagName('image');
	$id = 1;
	foreach ($itemsId as $itemId) {
		  $itemId->setAttributeNode(new DOMAttr('id', $id));
		  ++$id;
	}
	$domtree->save("new_files.xml");
}

//Let's check if the current folder is "_altimage". If so, uploaded image data will not be stored in xml file.					
$findme  = '_altimage';
$pos = strpos($simplepath, $findme);

if ($pos === false) {				
	$deleteElementId = new DOMDocument('1.0', 'UTF-8');
	$deleteElementId->load("new_files.xml");

	$numberOfNodes = $deleteElementId->getElementsByTagName('image')->length;

	//We want 20 images as "Newest" . So, If xml file already include 20 images, script will delete oldest image data and save newest one.
	if ($numberOfNodes == 20) {
		$xpath = new DOMXpath($deleteElementId);
		$items = $xpath->query('/images/image[@id="1"]');
		foreach ($items as $item) {
			 $item->parentNode->removeChild($item);
		}				
		$deleteElementId->save("new_files.xml");
		loadXmlFile();
	} else {
		loadXmlFile();
	}
} else {
	echo "The string '$findme' was found";
}
And the example data in xml file:
Code
<?xml version="1.0" encoding="UTF-8"?>
<images>
     <image details="08.28.11" thumbnail="/content/gallery/pics/tn_PIC_0001.jpg" url="#/content/gallery/pics/PIC_0001.jpg" image_name="PIC_0001.jpg" id="1"/>
     <image details="08.28.11" thumbnail="/content/gallery/pics/tn_PIC_0002.jpg" url="#/content/gallery/pics/PIC_0002.jpg" image_name="PIC_0002.jpg" id="2"/>
     <image details="08.28.11" thumbnail="/content/gallery/pics/tn_PIC_0003.jpg" url="#/content/gallery/pics/PIC_0003.jpg" image_name="PIC_0003.jpg" id="3"/>
     ...
</images>
The images are sorted by the "id" tag. So, first image will always be oldest. For reverse images order (newest->oldest), remember put the folowing code in your flash module:
Code
var childItems=this.firstChild.childNodes;
childItems.reverse();
One thing I can't figure out - how to disable operations on xml file when folder is hidden or protected by password. I've trying this, but doesn't works :| :
Code
$folder = ivMapperFactory::getMapper('folder')->find(ROOT_DIR . $this->path);
if ($folder->hidden == 'false') {
     my_action...
}else{
     echo "Folder is Hidden";
}
	
 
User avatar
Nick
Imagevue Hitman
Posts: 2872
Joined: 02 May 2006, 09:13

Re: Run script when done uploading

02 Sep 2011, 11:36

You are doing great I see, just use $folder->isHidden() and $folder->hasPassword().
firedev.com