Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the flow-php-server #3

Open
tombujok opened this issue Jun 20, 2014 · 22 comments
Open

How to use the flow-php-server #3

tombujok opened this issue Jun 20, 2014 · 22 comments

Comments

@tombujok
Copy link

Hi,

Is there a small example available how to use the flow-php-server from scratch?

Thanks
Tom

@120dev
Copy link

120dev commented Jun 24, 2014

+1 for example plz

@AidasK
Copy link
Member

AidasK commented Jun 24, 2014

Basic usage example at readme.md is almost complete, just put it to php file:

index.php:

if (\Flow\Basic::save('./final_file_destination', './chunks_temp_folder')) {
  // file saved successfully and can be accessed at './final_file_destination'
} else {
  // This is not a final chunk or request is invalid, continue to upload.
}

We can also improve it by providing our config class and request class:

index.php:

$config = new Config(array(
   'tempDir' => './chunks_temp_folder'
));
$request = new Request();
if (\Flow\Basic::save('./final_file_destination', $config, $request)) {
  // file saved successfully and can be accessed at './final_file_destination'
} else {
  // This is not a final chunk or request is invalid, continue to upload.
}

Now, we have access to flow.js request params, because we have created Request class.
Please look for available getters here: https://github.com/flowjs/flow-php-server/blob/master/src/Flow/Request.php

Our final index.php:

$config = new Config(array(
   'tempDir' => './chunks_temp_folder'
));
$request = new Request();
if (\Flow\Basic::save(__DIR__ . '/' . $request->getFileName(), $config, $request)) {
  echo "Hurray, file was saved in " . __DIR__ . '/' . $request->getFileName();
}
// In most cases, do nothing, \Flow\Basic handles all errors

For more detailed explanation, please look inside the source: https://github.com/flowjs/flow-php-server/blob/master/src/Flow/Basic.php

Flow.js configuration:

var flow = new Flow({
  target:'index.php'
});
flow.assignBrowse(document.getElementById('browseButton'));
flow.on('fileSuccess', function(file,message){
    console.log(file,message);
    alert("File was uploaded: " + message);
});
flow.on('filesSubmitted', function(file) {
   flow.upload();// instant upload
});

@tombujok
Copy link
Author

Thanks.
I am sorry, but I am new to PHP - how can I include/import the "flow-php-server" server code in the index.php cass.?
How should the folder structure look like?

@AidasK
Copy link
Member

AidasK commented Jun 24, 2014

Sorry, I can't teach you PHP, but I can give you some hints:

@120dev
Copy link

120dev commented Jun 24, 2014

Hello,

I have exactly the same issue Tombujok, I see only classes but nothing that's instantiated, how to load these classes?

I tested:

<code
require_once('flow-php-server/src/Flow/Basic.php');
$config = new Config(array(
'tempDir' => './chunks_temp_folder'
));
$request = new Request();
if (\Flow\Basic::save('./final_file_destination', $config, $request)) {
// file saved successfully and can be accessed at './final_file_destination'
die(json_encode([
'success' => true,
'files' => $_FILES,
'get' => $_GET,
'post' => $_POST,

    ]));
} else {
    // This is not a final chunk or request is invalid, continue to upload.
    die(json_encode([
        'success' => false,
        'files'   => $_FILES,
        'get'     => $_GET,
        'post'    => $_POST,

    ]));
}

Return : Fatal error: Class 'Config' not found in /var/www/wamteam/PHP/controler.php on line 32

@tombujok
Copy link
Author

No, it's not about teaching PHP - it's about usability.

In the Java world we normally create a sample project that simply works -
you just take it and use it.
Code snippets are cool, but it's time consuming to put it all together-
and everybody does the same thing all the time...
It would be great to have a sample PHP project with the working service - I
could just grab it and copy to my Apache...

On Tue, Jun 24, 2014 at 4:47 PM, Aidas Klimas [email protected]
wrote:

Sorry, I can't teach you PHP, but I can give you some hints:


Reply to this email directly or view it on GitHub
#3 (comment)
.

@AidasK
Copy link
Member

AidasK commented Jun 24, 2014

If you are using composer, then your index.php should start with:

<?php
// path to composer autoloader
require_once( __DIR__ . '/../vendor/autoload.php');
...

Without composer:

<?php
require_once(__DIR__ . '/../src/Flow/Autoloader.php');
Flow\Autoloader::register();
....

Hope this helps

@120dev
Copy link

120dev commented Jun 24, 2014

Thanks works great after
composer install (path flow-php-server/)

and load autoload.php in vendor.

Thanks

@ajschmaltz
Copy link

Alright! Got this working with Laravel. There were some problems but I recreated the basic class and it's looking good.

@jesusp
Copy link

jesusp commented Oct 23, 2014

Hello, I'm trying implementing this at YII Framework, but I have some problems because my application make a lot of GET and POST request to send chunks.

I understand that, but my question is.

why GET requests return a "404 not found"?

or even

how can I avoid the GET Requests to use just POST?

@ImanMh
Copy link
Contributor

ImanMh commented Dec 18, 2014

I'm also having an issue with using this library:

This is the first lines in my flow-php-server/src/index.php

<?php
    require_once( __DIR__ . '/../vendor/autoload.php');

but I'm getting this error:

Fatal error: Class 'Config' not found in /Users/Iman/Documents/experiments/flow.js/flow-php-server/src/index.php on line 4

should I use this at top of my index.php?

namespace Flow;

When I add the namespace, I get 404 and "Provisional headers are shown" errors in my browser network panel.

What am I missing?

@jesusp
Copy link

jesusp commented Dec 18, 2014

I solved the problem I had by doing the next steps:

1.- include the files and using the following namespaces:

require_once(dirname(FILE) . "/../extensions/vendors/Flow/Autoloader.php");
use Flow\Autoloader as FAutoloader;
use Flow\Config as FConfig;
use Flow\Request as FRequest;
use Flow\Basic as FBasic;

2.- instantiate config and Request:

 FAutoloader::register();
$config = new FConfig(['tempDir'=>$tmpDir]);
$request = new FRequest();

3.- call the Static function save in Basic passing the required parameters:

FBasic::save($fileName, $config, $request);

and finally in the JavaScript file I changed a property called testChunks which is normally "true" to "false", that's to avoid lots of GET requests!.

I hope those steps work for you!.

@ImanMh
Copy link
Contributor

ImanMh commented Dec 18, 2014

I solved my problem by copy pasting the source code of Node.js sample into my html file that I was using to select files to upload. I think I was making a mistake in my JavaScript.
Any way I think there would be awesome if there was a working samlpe of flow.js and flow-php-server integration available.

@batusa
Copy link

batusa commented Jan 23, 2015

@jesusp thanks for the advice! it helped me to make flow.js work out on Yii.

@jesusp
Copy link

jesusp commented Jan 23, 2015

@batusa You're welcome it's always a great pleasure to contribute with comments!. I feel very well because that worked well for you!...

@ivigr
Copy link

ivigr commented Feb 2, 2015

my frontend seems to run well and pictures are uploaded, chrom console like below:

catchAll
["fileAdded", e, Event]
shop.js:98
catchAll
["filesAdded", Array[1], Event]
shop.js:98
catchAll
["filesSubmitted", Array[1], Event]
shop.js:98
catchAll ["uploadStart"] shop.js:98
catchAll
["fileProgress", e, f]
shop.js:98
catchAll ["progress"] shop.js:98
catchAll
["fileSuccess", e, "<script language='javascript' type='text/javascript'>window.location.href='user/#/login/0';</script>", f]
shop.js:98
catchAll ["complete"]

but in fact flow listeners are not called, console.log nothing. The code like this:

//flow event listener
var flow = new Flow({});
flow.on('fileSuccess', function(file,message){
console.log(file,message);
});
flow.on('filesSubmitted', function(file) {
console.log('filesSubmitted');
flow.upload();// instant upload
});

and nothing is happened in backend.

I am sorry to ask the same question again, Is there a full example available how to use the flow-php-server from scratch?

much appreciated.

@viruskst
Copy link

help::
i used flow.js php server to upload a file and its working
the only problem i faced is the file is uploaded with out extension for example jpg
an image file was uploaded as
filenamejpg and the file is not opening.

@ofix
Copy link

ofix commented Dec 27, 2015

Without any third-party php framework in my php server side, when using this library I also encountered the problem that Class 'Config' not found. I fixed it as following, may it would help.

require_once (DIR.'/../lib/flow-php-server/src/Flow/Autoloader.php');
Flow\Autoloader::register();
$config = new Flow\Config(array(
'tempDir' => DIR.'./../upload/chunks_temp_folder'
));
$file = new \Flow\File($config);

@muhammadyibr
Copy link

@jesusp having testChunks to false worked for me

Thanks

@aklassen
Copy link

@viruskst Do you already have an solution for your extension problem? I'm having similar issues here as well.

@muhammadyibr
Copy link

@aklassen do you have testChunks as false?

@vasimlook
Copy link

vasimlook commented Jul 25, 2020

is it possible can i save at the time of submit form
in PHP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests