Hello everyone.
I’m new in Modx.
I’m trying to launch runSnippet command (phpthumbof), but I’m still keep getting error .
There is html form. Submitting the form ajax sends data to php file.
php
<?php
// modx api
define('MODX_API_MODE', true);
require $_SERVER['DOCUMENT_ROOT'].'/index.php';
....
$options = "w=100&h=100&zc=1&far=C&q=95";
$image = $_SERVER["REQUEST_SCHEME"] . '://' . $_SERVER["SERVER_NAME"].'/user_upload/'.$fileName; // it's ok
$userImage = $modx->runSnippet('phpthumbof', array('input' => $image, 'options' => $options)); // if I comment this line I won't get the error
echo json_encode(['error' => '<img src="'.$userImage.'" alt="">'], JSON_UNESCAPED_UNICODE);
exit;
....
The error is {"readyState":4,"responseText":"","status":500,"statusText":"error"}
Maybe you could check the error-log of your server to see what the actual error message is.
The runSnippet-call looks good to me. Perhaps $modx isn’t initialized correctly.
Maybe check this site as the MODX_API_MODE seems to be deprecated anyway.
Like @halftrainedharry said, check your PHP error log for details of the error. A 500 status can mean anything, and the PHP error log will immediately tell you what it is.
Likely there’s something wrong in your file, or pThumb/phpthumbof expects to have access to something (perhaps a context or resource) which you’re not initializing.
Hello. Like I said if I comment the line $image = $_SERVER....... everything works fine. That’s mean there are no errors in my file. That’s mean the problem is runSnippet line or I didn’t include some important Modx methods || files || processors || etc… in my file.
One interesting thing I’m thinking about the whole day is that I’ve got another html page where I call a snippet - [[!check]]. Inside this snippet I call phpthumbof jus like $avatar = $modx->runSnippet('phpthumbof', array('input' => $var, 'options' => $options)); You know what? It works just fine. $var is https://site.com/user_upload/avatar.jpg. Why? Why does 2st snippet work by calling it inside 1st snippet? Can some of you create a file, include Modx API and try to simulate my situation?
That completely depends on your server configuration and is independent of MODX entirely.
Common locations are within a server control panel, /usr/local/apache/logs/error_log, var/log/httpd/error_log, /var/log/apache2/error.log, as error_log files in the directory the error was triggered in, or elsewhere. On MODX Cloud it’s in your home directory > log.
If you check the phpinfo() output (which MODX has a utility for, in manage > reports > system info > phpinfo()) find the error_log directive. That normally points to the location for the error log. However if that’s empty, it may not write logs anywhere and you’ll need to edit the php.ini or ask you host.
Finally if there’s no way to track it down, adding these two lines in your php file may allow the error message to be shown on screen instead:
Again this is not related to MODX but basic debugging of any php application. Google information specific to how your server is setup if you still can’t find it with this.
PHP Fatal error: Uncaught Error: Call to a member function runSnippet() on null in /home/…/public_html/theme/RedirectModxApiAjax/RedirectModxApiAjax.php:225\nStack trace:\n#0 /home/…public_html/theme/RedirectModxApiAjax/RedirectModxApiAjax.php(248): tryUpload(Array)\n#1 {main}\n thrown in /home/…/public_html/theme/RedirectModxApiAjax/RedirectModxApiAjax.php on line 225, referer https://site.com/sign-up?
tryUpload() is a function where I’m trying to runSnippet. runSnippet is line 225
This means, that $modx is null. If you instantiated $modx in a different function then probably the scope of this variable is wrong. Maybe you can pass $modx as a parameter to the function tryUpload().