---
title: "Debugging PHP ActiveX/Java Upload Scripts"
canonical: https://www.aurigma.com/docs/us8/debugging-php-upload-scripts-iu.htm
product: "Upload Suite 8"
---

# Debugging PHP ActiveX/Java Upload Scripts
 
This topic describes different approaches to solving the issue when ActiveX/Java Uploader is unable to successfully upload files and displays the following error message:
![500: Internal Server Error](https://www.aurigma.com/docs/us8/InternalServerErrorPhp.png)
Sometimes you may see the message saying that upload is successful, but files appear to be not uploaded; this may indicate a server error, but not necessarily.

In this case, please, firstly check that you specified at least one [Converter](https://www.aurigma.com/docs/us8/JA_T_P_Converter.htm.md), your upload script actually saves files (see the [Saving Uploaded Files in ActiveX/Java Uploader PHP](https://www.aurigma.com/docs/us8/saving-uploaded-files-in-php-iu.htm.md) topic), and you are looking for files in the correct folder.

Here are the most probable issues causing the server-side error:

- ActiveX/Java Uploader cannot save uploaded files because of wrong permissions configuration. See the [Configuring ActiveX/Java Uploader PHP](https://www.aurigma.com/docs/us8/configuring-php-iu.htm.md) topic to learn how to set required permissions.
- The request size is too big. See the [Configuring ActiveX/Java Uploader PHP](https://www.aurigma.com/docs/us8/configuring-php-iu.htm.md) topic to learn how to increase maximum request length.
- There is an error in your upload script (specified with the [UploadSettings.ActionUrl](https://www.aurigma.com/docs/us8/JA_P_P_UploadSettings_ActionUrl.htm.md) property). See the debug approaches described below to find the error.

**Note** 
If you experience an issue having different sympthoms than those described in this article, please, see the [Basic Steps in Troubleshooting of ActiveX/Java Uploader](https://www.aurigma.com/docs/us8/troubleshooting-basic-steps.htm.md) topic.
 
Here we consider the following approaches to handling and debugging server-side errors:

- Error logging approach is more convenient for production applications. It catches all the exceptions and writes error details to a log file; it does not show any information about errors to users.
- Event handling approach implies showing the server response when some error occurs. If displaying errors is enabled, this response contains error details. However, this approach requires some modifications of ActiveX/Java Uploader settings.
- Using sniffer allows you to view server response without necessity to modify embedding code, but it uses a third-party tool.
- Running script in debug mode means debugging PHP scripts in the same manner as standalone applications.

## Error Logging
 
PHP configuration file (`php.ini`) contains the **Error handling and logging** section which controls how errors are handled and reported. To configure error logging set the following parameters:
 ```
error_reporting  =  E_ALL
log_errors = On
``` 
The first parameter defines what error levels should be handled. We set `E_ALL` which means: all errors, warnings, and notices. The second one states whether these error reports should be written to a log file. If `On`, as we have set, error messages will be written to the `<Apache installation folder>\logs\error.log` file in the following way:
 
`[Mon Oct 18 12:27:53 2010] [error] [client 127.0.0.1] PHP Warning: require_once(ImageUploaderPHP/UploadHandle.class.php) [function.require-once]: failed to open stream: No such file or directory in C:\\htdocs\\PhpLibrarySample\\upload.php on line 2, referer: http://localhost/PhpLibrarySample/imageuploaderphp/scripts/imageuploader.jar`
 
Optionally, you can set a limitation for the error file length using the `log_errors_max_len` parameter.

## Event Handling
 
If you are not familiar with the client events in ActiveX/Java Uploader, please, read the [Using JavaScript API](https://www.aurigma.com/docs/us8/using-javascript-api.htm.md) topic first.
 
ActiveX/Java Uploader provides two events which are helpful for debugging, namely, [Error](https://www.aurigma.com/docs/us8/JA_E_Uploader_Error.htm.md) and [AfterUpload](https://www.aurigma.com/docs/us8/JA_E_Uploader_AfterUpload.htm.md). The first one fires when a server or client-side error occurs, and the second fires when an upload is supposed to be successful. We recommend you to handle both events simultaneously to get debug information on server errors because there is a known problem with PHP applications: they can return HTTP code 200 (in our case it means successful upload) even if some error occurs.
 
The **Error** event provides detailed description of an occurred error through the **errorPage** parameter which represents the web page returned from the server. To ignore non-server errors you can use the **errorCode** argument, since it is equal to `4` in case of internal server error. For the full list of error codes, please, see the [Error event parameters](https://www.aurigma.com/docs/us8/JA_E_Uploader_Error.htm.md) paragraph.
 
The idea of catching errors via the **AfterUpload** event is as follows:
 
1. Make your upload script to return some predefined response after all the uploaded files were saved.
2. In the **AfterUpload** event handler check whether a string returned by the **response** parameter contains the predefined one.
3. If this check is failed, it means that an error has occurred and the **response** parameter contains the error-related information.

Let us presume that server-side upload script returns a `"complete"` string (predefined response) after all the uploaded files were saved. This can be done as follows:
 ```
<?php
// ... save uploaded files

echo "complete";
?>
``` 
The following example shows how to display error details if a server-side error occurs.
 ```
<script type="text/javascript">
function showErrorWindow(errorMessage){
    var newWindow = window.open();
    with (newWindow.document) {
        open("text/html");
        write("A server error occured<br/>");
        write("Error Message: " + errorMessage);
        close();
    }
}

function errorHandler(errorCode, httpResponseCode, errorPage, additionalInfo){
    //Occured error is a server error
    if (errorCode == 4) {
        showErrorWindow(errorPage);
    }
}

function afterUploadHandler(response){
    //Some server-side error occurred
    if (response.indexOf("complete") > -1){
        showErrorWindow(response);
    }
}
</script>

<?php
    require_once "ImageUploaderPHP/Uploader.class.php";
    $uploader = new Uploader('Uploader1');
    $uploader->getClientEvents()->setError("errorHandler");    
    $uploader->getClientEvents()->setAfterUpload("afterUploadHandler");    
    $uploader->render();
?>
``` 
**Note** 
If error details are not displayed, make sure that `display_errors` parameter in your `php.ini` is set to `On`.

## Using Sniffer
 
As an example of network analyzer tool we use the [Fiddler↗](http://www.fiddler2.com/). Here we discuss how to use it to debug server-side upload script.
 
1. Open `index.php` in your browser. If it is able to send traffic to Fiddler, the corresponded session will be displayed in the **Web Sessions** pane of the tool.
2. Send a file via ActiveX/Java Uploader.
3. Double-click the `upload.php` session in the **Web Sessions** pane.
 ![Using Fiddler to debug upload script in PHP](https://www.aurigma.com/docs/us8/DebuggingPhpUploadScriptsFiddler.png) 
    Find upload session details in the left part of Fiddler's interface. Here it contains the POST request sent by ActiveX/Java Uploader and the response returned by your upload script. If your upload script contains an error this error details will be displayed in the returned response.
 
**Note** 
If error details are not displayed, make sure that `display_errors` parameter in your `php.ini` is set to `On`.

## Running Script in Debug Mode
 
Basically, PHP does not support debugging, but you can use third-party debuggers, such as [Xdebug↗](http://xdebug.org/). You may use Xdebug with different IDEs (for example, with Eclipse), the [Debugging PHP applications with xdebug↗](http://devzone.zend.com/article/2930) article tells how to use Xdebug with Eclipse.
 
As well, you may use an IDE which supports debugging PHP scripts, such as [CodeLobster PHP Edition↗](http://codelobster.com/).

## See Also
 
### Reference
 
- [Error Event](https://www.aurigma.com/docs/us8/JA_E_Uploader_Error.htm.md)
- [UploadSettings.ActionUrl Property](https://www.aurigma.com/docs/us8/JA_P_P_UploadSettings_ActionUrl.htm.md)
- [Converter Class](https://www.aurigma.com/docs/us8/JA_T_P_Converter.htm.md)

### Manual
 
- [Saving Uploaded Files in ActiveX/Java Uploader PHP](https://www.aurigma.com/docs/us8/saving-uploaded-files-in-php-iu.htm.md)
- [Configuring ActiveX/Java Uploader ASP.NET](https://www.aurigma.com/docs/us8/configuring-aspnet-iu.htm.md)
- [Basic Steps in Troubleshooting of ActiveX/Java Uploader](https://www.aurigma.com/docs/us8/troubleshooting-basic-steps.htm.md)

### Other Resources
 
- [Fiddler↗](http://www.fiddler2.com/)
- [CodeLobster PHP Edition↗](http://codelobster.com/)
- [Xdebug↗](http://xdebug.org/)
- [Debugging PHP applications with xdebug↗](http://devzone.zend.com/article/2930)
