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

I must be doing something wrong. #39

Closed
arisslavov opened this issue Dec 12, 2016 · 3 comments
Closed

I must be doing something wrong. #39

arisslavov opened this issue Dec 12, 2016 · 3 comments
Labels

Comments

@arisslavov
Copy link

arisslavov commented Dec 12, 2016

So after uploading the folder to my host, i proceeded to run
"php ../../../composer.phar require recanalyst/recanalyst"
from my SSH via PuTTY

I then tried to upload a file into this php file

<?php

require __DIR__ . '/src/vendor/autoload.php';

use RecAnalyst\RecordedGame;

$array = array();
$a = __DIR__ . "/games/" . $_FILES["file"]["name"][0];
move_uploaded_file($_FILES["file"]["tmp_name"][0], $a);
$array[] = $_FILES["file"]["name"][0];
foreach ($array as $val) {
    $filename = __DIR__ . '/games/' . $val;
// Read a recorded game from a file path.
    $rec = new RecordedGame($filename);
// Render a map image. Map images are instances of the \Intervention\Image
// library, so you can easily manipulate them.
    $rec->mapImage()
        ->resize(240, 120)
        ->save('minimap.png');
// Display players and their civilizations.
    echo 'Players: ' . "\n";
    foreach ($rec->players() as $player) {
        echo ' * ' . $player->name . ' (' . $player->civName() . ')' . "\n";
    }
    echo 'Minimap saved in minimap.png.' . "\n";
}

Which is pretty much the basic example with a simple twist that it takes the uploaded file and puts it into the folder and then passes it to RecAnalyst.

After trying to upload a file, i came accross this error in the log files.

mod_fcgid: stderr: PHP Fatal error: Class 'RecAnalyst\RecordedGame' not found in ********/httpdocs/recanalyst/recanalyst.php on line 16

As i'm a complete newbie to Composer and stuff, i'm guessing there's something that went wrong when trying to load via autloader.php

The directory structure is something like this
capture

Can i get some pointers in the right direction if you got the time?

Regards,
Ray.

@goto-bus-stop
Copy link
Owner

goto-bus-stop commented Dec 13, 2016

Hi! It looks like you're running composer require inside the cloned repository. With Composer, you don't need to manually clone or download RecAnalyst, but instead Composer downloads it and its dependencies for you and generates the autoloader. The examples don't use Composer quite in that way because I wanted them to work just after cloning the repository. It's a bit unclear, so maybe I should add a note about that in the Readme :)

To use RecAnalyst in a real application, you'd put only your own files in a directory. Then you'd run composer require recanalyst/recanalyst in that directory to download RecAnalyst. Composer will create a vendor directory for you and put the autoloader in it. Then you'd include that autoload.php.

Your project layout should end up looking something like this:

├── composer.json # This is where Composer saves that you want recanalyst/recanalyst
├── composer.lock # This is where Composer saves which dependencies it installed exactly
├── simple.php # This is your own PHP file...
└── vendor/
    ├── autoload.php # ...and this is the file you need to include.
    ├── composer/
    ├── guzzlehttp/
    ├── intervention/
    ├── psr/
    └── recanalyst/

And simple.php could look a bit like this:

// VERY stripped-down version of the simple.php example!

require 'vendor/autoload.php'; // ← different from how it's done in the example!

use RecAnalyst\RecordedGame;

// And the rest is your own code.
$rec = new RecordedGame('/path/to/a/game.mgx');
$rec->mapImage()
    ->resize(240, 120)
    ->save('minimap.png');
echo 'Minimap saved in minimap.png.' . "\n";

Hope that helps!

@goto-bus-stop
Copy link
Owner

Closing for now—feel free to reopen if you have more questions :)

@arisslavov
Copy link
Author

arisslavov commented Dec 26, 2016

After your reply i tried that.
It seems to be throwing a 500 fatal error:
mod_fcgid: stderr: PHP Fatal error: Class 'RecAnalyst\RecordedGame' not found in /recanalyst/recanalyst.php on line 14, referer: /recanalyst/index.html

It's on a php 5.6+ host so that's out of the question.

The current code is as follows:

<?php

require 'vendor/autoload.php';

use RecAnalyst\RecordedGame;

$array = array();
$a = __DIR__ . "/games/" . $_FILES["file"]["name"][0];
move_uploaded_file($_FILES["file"]["tmp_name"][0], $a);
$array[] = $_FILES["file"]["name"][0];
foreach ($array as $val) {
    $filename = __DIR__ . '/games/' . $val;
// Read a recorded game from a file path.
    $rec = new RecordedGame($filename);
// Render a map image. Map images are instances of the \Intervention\Image
// library, so you can easily manipulate them.
    $rec->mapImage()
        ->resize(240, 120)
        ->save('minimap.png');
// Display players and their civilizations.
    echo 'Players: ' . "\n";
    foreach ($rec->players() as $player) {
        echo ' * ' . $player->name . ' (' . $player->civName() . ')' . "\n";
    }
    echo 'Minimap saved in minimap.png.' . "\n";
}

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

No branches or pull requests

2 participants