Fork me on GitHub

Announcement

The oneye project has been discontinued. You might not expect further fixes and support from us. All community related systems are set to read-only mode. Though feel free to download and use oneye as-is or even fork it over at GitHub.

#1 2015-01-28 23:12:43

sazearte
Member
From: France
Registered: 2013-10-23
Posts: 234

[FIXED] Address of a file

Hello, I am trying to create a oneye application.

I would like to access a user file how to do?

This is my code for acess file argument:

if (isset($params['arg'][0])) {
		$params[0] = $userDir . FILES_USER_DIR . '/' . $params['arg'][0];
	}

		$Open_File = str_replace(um('getCurrentUserDir').'files/', '/', $params[0]);
		$Open_File = str_replace('//', '/', $Open_File);

Why the file is not found?
This is location of $Open_File "Desktop/test.mp4"

Last edited by sazearte (2015-04-26 21:03:01)

Offline

#2 2015-02-03 01:31:37

lars-sh
Administrator
From: near Hamburg, Germany
Registered: 2011-07-14
Posts: 731
Website

Re: [FIXED] Address of a file

You Need to use the virtual file system (vfs) functions. To open a fle you could use the following code and there are a lot more functions.

function XXX_run($params = null) {
	$handler = vfs('open', array($params[0], 'w'));
}

Best regards,
Lars Knickrehm

The oneye project.

Offline

#3 2015-02-03 08:32:52

sazearte
Member
From: France
Registered: 2013-10-23
Posts: 234

Re: [FIXED] Address of a file

the value of $handler is : Resource id #135

It'is not a adresse file ?

Offline

#4 2015-02-03 12:16:37

lars-sh
Administrator
From: near Hamburg, Germany
Registered: 2011-07-14
Posts: 731
Website

Re: [FIXED] Address of a file

$params[0] is a virtual (!) path. It is not recommended to convert it into a file system address. Instead you are recommended to use the vfs functionality to handle it.
$handler is a resource - the same you get when calling "fopen" on a file system address.

Tip: In case you really need the file system addresses instead of the vfs one, there're some conversion functions inside the set of vfs functions (see "system_xxxxxxxxxx/system/services/vfs/modules/vfs.eyecode").


Best regards,
Lars Knickrehm

The oneye project.

Offline

#5 2015-02-03 13:43:41

sazearte
Member
From: France
Registered: 2013-10-23
Posts: 234

Re: [FIXED] Address of a file

I made a oneye application that needs a .txt file.

I want to just enter the file, for example if it is in the office.

The user do "opens with my apllication" his works, but it does not find the .txt file

Offline

#6 2015-02-05 15:12:41

lars-sh
Administrator
From: near Hamburg, Germany
Registered: 2011-07-14
Posts: 731
Website

Re: [FIXED] Address of a file

Please zip your code and send it to me via mail, so I can check it directly.


Best regards,
Lars Knickrehm

The oneye project.

Offline

#7 2015-02-05 15:49:53

sazearte
Member
From: France
Registered: 2013-10-23
Posts: 234

Re: [FIXED] Address of a file

ok thanks, my code is :
http://pastebin.com/jnQKKsqj

it's code of the file app.eyecode

Offline

#8 2015-02-05 16:58:04

lars-sh
Administrator
From: near Hamburg, Germany
Registered: 2011-07-14
Posts: 731
Website

Re: [FIXED] Address of a file

$handler

is a PHP resource. Please take a look at http://php.net/manual/function.fopen.php for further information.


Best regards,
Lars Knickrehm

The oneye project.

Offline

#9 2015-02-05 19:09:51

sazearte
Member
From: France
Registered: 2013-10-23
Posts: 234

Re: [FIXED] Address of a file

Yes, so I have to use $handler
but rather:

$File = str_replace(um('getCurrentUserDir').'files/', '/', $params[0]);

Offline

#10 2015-02-06 09:52:59

lars-sh
Administrator
From: near Hamburg, Germany
Registered: 2011-07-14
Posts: 731
Website

Re: [FIXED] Address of a file

OK, got what you're doing.

Insert the following into your app.eyecode and use $url to access the video file from inside your HTML code:

$myHidden = new Hidden(array(
	'father' => 'eyeIframize_Window_Content',
	'name' => 'eyeIframize_Hidden',
	'text' => $params[0]
));
$myHidden->show();

$url = 'index.php?checknum=' . $checknum . '&msg=getFile';

Now add a new function to the events.eyecode just as the following:

function mediaplayer_on_getFile($params = null) {
	// Get the input URL back from the "Hidden" widget
	$url = $GLOBALS['mediaplayer_Hidden']->text;
	
	// Clean some path relevant things
	$filename = basename($url);
	$path = eyeFiles('cleanPath', array(substr(trim($url, '/\\'), 0, -strlen($filename)))); // utf8
	
	// Specify the file's content length
	header('Accept-Ranges: bytes');
	if ($path[1] === 'real') {
		header('Content-Length: ' . vfs('real_filesize', array($path[0] . '/' . $filename)));
	} else {
		header('Content-Length: ' . vfs('filesize', array($path[0] . '/' . $filename)));
	}
	
	// Specify the file's content type
	header('Content-Type: video/mp4');
	
	// Echo the file content
	if ($path[1] === 'real') {
		vfs('printFile', array($path[0] . '/' . $filename));
	} else {
		vfs('readFile', array($path[0] . '/' . $filename));
	}
	
	// Exit the HTTP request
	exit;
}

Summary: The file cannot be accessed directly. You need to create such a checknum based URL first. It is used to call an application specific event function (here: "getFile"). From there you can echo the video file.


Best regards,
Lars Knickrehm

The oneye project.

Offline

#11 2015-02-07 19:37:26

sazearte
Member
From: France
Registered: 2013-10-23
Posts: 234

Re: [FIXED] Address of a file

Thank you for your help

Unfortunately its not market the file not found

Here HTML5 code:

    <source type="video/mp4" src="'.$url.'" />

and $url=index.php?checknum=255855972738&msg=getFile

Last edited by sazearte (2015-02-07 19:39:26)

Offline

#12 2015-02-07 19:54:11

lars-sh
Administrator
From: near Hamburg, Germany
Registered: 2011-07-14
Posts: 731
Website

Re: [FIXED] Address of a file

Please open that URL manually and check the HTTP headers and eventually PHP error messages. What do you get?

PS: Remember to use htmlspecialchars to make sure special HTML characters are encoded correctly:

   <source type="video/mp4" src="' . htmlspecialchars($URL, ENT_QUOTES, 'UTF-8') . '" />

Last edited by lars-sh (2015-02-07 20:04:32)


Best regards,
Lars Knickrehm

The oneye project.

Offline

#13 2015-02-08 12:30:06

sazearte
Member
From: France
Registered: 2013-10-23
Posts: 234

Re: [FIXED] Address of a file

there is no php error.
There are no changes, the address was not found.

Thank you anyway.

Offline

#14 2015-02-08 12:47:06

lars-sh
Administrator
From: near Hamburg, Germany
Registered: 2011-07-14
Posts: 731
Website

Re: [FIXED] Address of a file

I'd like to see your code once more, please.


Best regards,
Lars Knickrehm

The oneye project.

Offline

#15 2015-02-08 14:47:22

sazearte
Member
From: France
Registered: 2013-10-23
Posts: 234

Re: [FIXED] Address of a file

Offline

#16 2015-02-08 15:04:18

lars-sh
Administrator
From: near Hamburg, Germany
Registered: 2011-07-14
Posts: 731
Website

Re: [FIXED] Address of a file

1) You need to edit the Hidden widgets parameters:

$myHidden = new Hidden(array(
	'father' => 'Gmail_WND',
	'name' => 'mediaplayer_Hidden',
	'text' => $params[0]
));
$myHidden->show();

And finally you need to put an info.xml file into your application's folder. Just copy one from eyeMedia and edit it or similar.


Best regards,
Lars Knickrehm

The oneye project.

Offline

#17 2015-02-08 17:26:00

sazearte
Member
From: France
Registered: 2013-10-23
Posts: 234

Re: [FIXED] Address of a file

Yes, in info.xml, i have     <openWith>1</openWith>


The market still does not, I give you the full application:
https://www.dropbox.com/s/ll8wfn5wk8ivi … r.zip?dl=0

Offline

#18 2015-02-08 17:34:53

lars-sh
Administrator
From: near Hamburg, Germany
Registered: 2011-07-14
Posts: 731
Website

Re: [FIXED] Address of a file

I just tested your app and receiving the file through that link works correctly.

Maybe there is some more server control required to get a HTML video running, I don't know.


Best regards,
Lars Knickrehm

The oneye project.

Offline

#19 2015-02-08 21:58:44

sazearte
Member
From: France
Registered: 2013-10-23
Posts: 234

Re: [FIXED] Address of a file

I use WampServer without any change to the original configuration.
I'll test on Linux


Have you opened an mp4 video, with the option to open with?

Last edited by sazearte (2015-02-08 22:06:57)

Offline

#20 2015-02-10 14:22:31

sazearte
Member
From: France
Registered: 2013-10-23
Posts: 234

Re: [FIXED] Address of a file

you managed to play a video?

Offline

#21 2015-02-26 12:18:14

sazearte
Member
From: France
Registered: 2013-10-23
Posts: 234

Re: [FIXED] Address of a file

To make testes, I created a simple application that display txt files.
But its not working, but I'm back your old code

contained the file does not appear

https://www.dropbox.com/s/5762t9zh6x1a62k/txt.zip?dl=0

app.eyecode

<?php

function txt_run($params= '') {

	global $checknum;
	global $myPid;
	$currentUser;
	$userDir = um('getCurrentUserDir');



	$myWindow = new Window(array(
		'name' => 'Gmail_WND',
		'father' => 'eyeApps',
		'cent' => 1,
		'width' => $_SESSION['SCREEN']['eyeApps']['width'],
		'height' => $_SESSION['SCREEN']['eyeApps']['height'],
		'x' => 0,
		'y' => 3,
		'title' => 'txt',
		'sendResizeMsg'=>1,
		'sigResize'=>'Resize'
	));
	$myWindow->show();
	
$myContainer = new Container(array(
	'father' => 'Gmail_WND',
	'height' => $height,
	'name' => test,
	'width' => 1000,
	'x' => 1,
	'y' => 20
));


$myHidden = new Hidden(array(
	'father' => 'Gmail_WND',
	'name' => 'txt_Hidden',
	'text' => $params[0]
));
$myHidden->show();

$url = 'index.php?checknum=' . $checknum . '&msg=getFile';
		
		
$myContainer->show();

	$contenu=file_get_contents($url); 
	//echo "<br><br>Contenu du fichier $file : <br><pre>$contenu</pre>";
$myContainer->setContent('<br><br>the file '.$url.' : <br><pre>'.$contenu.'</pre>');
}

function txt_end($params= '') {
	reqLib('eyeWidgets','unserialize');
}
?>

events.eyecode

<?php
/*
  ___  _ __   ___ _   _  ___
 / _ \| '_ \ / _ \ | | |/ _ \
| (_) | | | |  __/ |_| |  __/
 \___/|_| |_|\___|\__, |\___|
                  |___/

oneye is released under the GNU Affero General Public License Version 3 (AGPL3)
 -> provided with this release in license.txt
 -> or via web at www.gnu.org/licenses/agpl-3.0.txt

Copyright © 2005 - 2010 eyeos Team (team@eyeos.org)
             since 2010 Lars Knickrehm (mail@lars-sh.de)
*/


function txt_on_getFile($params = null) {
	// Get the input URL back from the "Hidden" widget
	$url = $GLOBALS['txt_Hidden']->text;
	
	// Clean some path relevant things
	$filename = basename($url);
	$path = eyeFiles('cleanPath', array(substr(trim($url, '/\\'), 0, -strlen($filename)))); // utf8
	
	// Specify the file's content length
	header('Accept-Ranges: bytes');
	if ($path[1] === 'real') {
		header('Content-Length: ' . vfs('real_filesize', array($path[0] . '/' . $filename)));
	} else {
		header('Content-Length: ' . vfs('filesize', array($path[0] . '/' . $filename)));
	}
	
	// Specify the file's content type
	header('Content-Type: video/mp4');
	
	// Echo the file content
	if ($path[1] === 'real') {
		vfs('printFile', array($path[0] . '/' . $filename));
	} else {
		vfs('readFile', array($path[0] . '/' . $filename));
	}
	
	// Exit the HTTP request
	exit;
}

function txt_on_Close($params=null) {
	txt_Stop();
	proc('end');
}

?>

Last edited by sazearte (2015-02-26 12:19:48)

Offline

#22 2015-02-28 17:56:04

lars-sh
Administrator
From: near Hamburg, Germany
Registered: 2011-07-14
Posts: 731
Website

Re: [FIXED] Address of a file

Using the correct mime type it works wink

header('Content-Type: text/plain');

Best regards,
Lars Knickrehm

The oneye project.

Offline

#23 2015-02-28 18:10:30

sazearte
Member
From: France
Registered: 2013-10-23
Posts: 234

Re: [FIXED] Address of a file

Thank you for your help, but its still not working.

Last edited by sazearte (2015-02-28 18:10:59)

Offline

#24 2015-03-04 10:57:33

sazearte
Member
From: France
Registered: 2013-10-23
Posts: 234

Re: [FIXED] Address of a file

1) That you it works with you?
2) which version are you using?
I used one of the master branch.

Offline

#25 2015-03-04 14:35:48

lars-sh
Administrator
From: near Hamburg, Germany
Registered: 2011-07-14
Posts: 731
Website

Re: [FIXED] Address of a file

Using the shown link it then displays me the txt file's content.

I'm using the latest oneye revision in master branch and the latest IE or the latest FF.


Best regards,
Lars Knickrehm

The oneye project.

Offline

Board footer

Powered by FluxBB