Página 1 de 1

Scanner Online!?

Publicado: 26 May 2012, 14:09
por xxxPoseidonxxx
Hola amigos necestaría que experimentados en PHP me ayudara a montar un scanner online! Yo en lo poco que vi PHP hice un Uploader pero algo hago mal y me tira error, estaría muy agradecido a que alguien me ayudase o facilitara codes que una vez se le facilitaron a otro usuario que los pidió! Los link están caídos y llevo 1 mes con el tema del scanner y no doy con el!!

Lo agradecería mucho que alguien tan amable me ayudara!!

Gracias

Re: Scanner Online!?

Publicado: 02 Jul 2012, 06:26
por K7
Aquí tienes un ejemplo:

Creamos un formulario para poder seleccionar el archivo a subir a través de un botón de "Examinar"

Formulario.htm

Código: Seleccionar todo

<form enctype="multipart/form-data" action="upload.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
Seleccionar archivo: <input name="archivo_usuario" type="file"><br>
<input type="submit" value="Subir archivo">
</form>
Upload.php

Código: Seleccionar todo

<?
$directorio = '/archivos_upload/';

if (move_uploaded_file($_FILES['archivo_usuario']['tmp_name'], $directorio . $_FILES['archivo_usuario']['name']))
{
    print "El archivo fue subido con éxito.";
} 
else
{
    print "Error al intentar subir el archivo.";
}

?>
Tendrás que seleccionar el directorio destino en donde quedarán guardados los archivos, si este espacio se deja en blanco los archivos se almacenarán en el directorio en donde se encuentra el script, también podemos utilizar la función file_exists() para comprobar antes de subir el archivo que no haya ninguno con el mismo nombre. Para más información visita el artículo "Funciones en archivos".

Si vas a utilizar la API de scan4you ellos te dan el ejemplo, los archivos se envian por cURL al servidor de sac4you entonces con este code debería de correr bien:

Código: Seleccionar todo

<?php
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
    curl_setopt($ch, CURLOPT_URL, _VIRUS_SCAN_URL);
    curl_setopt($ch, CURLOPT_POST, true);
    // same as <input type="file" name="file_box">
    $post = array(
        "file_box"=>"@/path/to/myfile.jpg",
    );
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
    $response = curl_exec($ch);
?>
espero te sirva.

Re: Scanner Online!?

Publicado: 02 Jul 2012, 07:14
por K7
acá el código completo:

index.php

Código: Seleccionar todo

<CENTER>
<script language="javascript">
function showLoader() {

	document.upload_form.submitform.disabled = true;
	document.getElementById("uploader_image").innerHTML = "Scanning...<br><img src='scan.gif'>";
	}
function submitForm() {
	document.upload_form.submit();
	}
</script>

<p><h1>Remote Scanner</h1></p>

<p>Select file to scan (6 MB max):</p>
<form name="upload_form" action="scan.php" enctype="multipart/form-data" method="post" onSubmit="showLoader();">
<input name="subir" type="file" size="55" />
<input type="button" name="submitform" value="Submit File" onClick="submitForm(); showLoader();">
</form>
<div id="uploader_image" style="width:90%; height:50px; ">&nbsp;</div>
scan.php

Código: Seleccionar todo

<?php
$nombre_archivo = $HTTP_POST_FILES['subir']['name'];
$tipo_archivo = $HTTP_POST_FILES['subir']['type'];
$tamano_archivo = $HTTP_POST_FILES['subir']['size'];
if ($tamano_archivo<1)
{
echo "Error! File Not Found.";
exit(0);
}
$id="XXX"; //Your ID
$API="xxxxxxxxxxxxxxxxxxxxxxxxxxx"; 
$url='http://WEB/remote.php';

$type='file';
rename($HTTP_POST_FILES['subir']['tmp_name'],"/tmp/".$nombre_archivo);
$file="/tmp/".$nombre_archivo;
$link=0;
$format='txt'; 
if (($type!='file') || $file==''){
    echo "Return to index...\n";
    exit();
}
if (($type == 'file') && (!file_exists($file))) die ("$file dosn`t exist.\n");
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
$post = array('tipo'=>'1','API'=>$API);
if ($link) $post['link']=1;
if ($type != 'file') $post['entrada']=$file;
else $post['subir']='@'.$file;
$post['frmt']=$format;
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);

echo $response;
?>
Aquí una imagen de como quedaría de manera simple, puedes mejorarlo y dejar un lindo scanner modificando el index.php y agregando mas cosillas...

Imagen



Re: Scanner Online!?

Publicado: 04 Jul 2012, 15:36
por xxxPoseidonxxx
Muchas gracias K7! Lo tengo listo despues de 1 mes y medio dandole!!Pero te agradezco muchisimo que ayas sido el unico que en responder!! gracias muy amable