How to Scan Documents in PHP Application

How to interact with TWAIN scanners in a PHP Application
access scanner in PHP

PHP is a popular server side language. However, it cannot interact with scanners attached to client computers. With the continued growth of digitization of documents, scanning capabilities are important in PHP environments.

To implement document scanning in your PHP web applications, you can use Dynamic Web TWAIN SDK to interact with TWAIN scanners attached to the client machine.

Image Scanning and Uploading in PHP Application

Here are the code snippets for using Dynamic Web TWAIN to scan documents and upload the images to web server in PHP.

JS code – scan and HTTP upload methods of Dynamic Web TWAIN 

function AcquireImage(){
            var DWObject = Dynamsoft.WebTwainEnv.GetWebTwain('dwtcontrolContainer');
            DWObject.IfShowUI = false;
            DWObject.SelectSource();
            DWObject.OpenSource();
            DWObject.AcquireImage();
        }
function btnUpload_onclick(){
DWObject.HTTPUploadThroughPostEx(
            strHTTPServer,
            DWObject.CurrentImageIndexInBuffer,
            strActionPage,
            uploadfilename,
            strImageType );
}

PHP code – action page for uploading the images to web server

<?php	
	$fileTempName = $_FILES['RemoteFile']['tmp_name'];	
	$fileSize = $_FILES['RemoteFile']['size'];
	$fileName = $_FILES['RemoteFile']['name'];
//**********************************
        $extraInfo = $_POST['ExtraInfo'];
//save extra info here
//**********************************

	if (file_exists($fileName)) 
		$fWriteHandle = fopen($fileName, 'w');
	else
		$fWriteHandle = fopen($fileName, 'w');
	$fReadHandle = fopen($fileTempName, 'rb');
	$fileContent = fread($fReadHandle, $fileSize);
	fwrite($fWriteHandle, $fileContent);
	fclose($fWriteHandle);
?>

Regarding Dynamic Web TWAIN

Dynamic Web TWAIN is a document scanning component that can run as an ActiveX control or browser plugin. It is used to interact with TWAIN devices, such as scanners, from popular web browsers. It is highly optimized for 32-bit/64-bit IE, Edge, Firefox, Chrome, Safari, and Opera on Windows and Mac OS X.

As far as Dynamic Web TWAIN is concerned, it doesn’t make much of a difference whether you are using C#, VB.NET, ASP, JSP or PHP on the server side. And, it can be deployed on web servers like IIS, Apache or Tomcat.

The server-side code can be written in your preferred language. “Action Page” refers to the page that receives and processes the images uploaded by Dynamic Web TWAIN. Images can be saved into a file system, database, SharePoint or other formats.

To embed web scanning module to your PHP application, you can download and install the 30-day free trial of Dynamic Web TWAIN.
Get 30-day free trial

Let us know if you have any questions or comments on writing a PHP application to interact with scanners.