Código HTML:
<script type="text/javascript" src="jquery-2.1.4.js">> { var iframe = document.getElementById("miIframe"); $.ajax({ type: "FILE", url: "save.php", data: { uploadedfile : uploadedfile } }).done(function( uploadfile ) { print iframe.src = uploadfile; }); } </script> <style> .b1{ padding: 4px; } .b2{ padding: 4px 100px; } #izq{ width:187px; height:650px; float:left; position: absolute; top: 20px; left: 50px; } #der{ width:187px; height:650px; float:rigth; position: absolute; top: 20px; left: 700px; } </style> <html> <head> <meta charset="utf-8"> <title>Captura de PDF File</title> </head> <body> <div id="izq"> <form enctype="multipart/form-data" name="form1" action="save_.php" method="POST"> <p align="left"><strong>BUSCAR PDF</strong></p> <p align="left"><input name="uploadedfile" type="file" size="80" maxlength="50" class="b1" onChange="lifra(this.value)"/></p> </form> </div> <div id="der"> <iframe id="miIframe" name="miIframe" src="" width="640" height="750"></iframe> </div> </body> </html> </div>
Código PHP:
<script language="Javascript">
function alertaGood(){
confirmar=alert("El archivo se ha subido con exito");
close();
}
function alertaBad(){
confirmar=alert("Ha ocurrido un error, trate de nuevo!");
close();
}
</script>
<?php
error_reporting(0);
$directorio = $_SERVER['DOCUMENT_ROOT'].'/pdf/';
$extension = pathinfo($_FILES['uploadedfile']['name']);
$extension = ".".$extension['extension'];
$info = @getimagesize($_FILES['uploadedfile']['tmp_name']);
$var_rand=rand(10000,999999)* rand(10000,999999);
$nombre_tem=md5($var_rand.$_FILES['uploadedfile']['name']);
$nombre=$nombre_tem.$extension;
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$directorio.$nombre))
{
echo "<body onload=alertaGood()> ";
}else
{
echo "<body onload=alertaBad()> ";
}
$axia="pdf/".$nombre;
return($axia);
?>