Verificar si existe el archivo y lanzar

mod_harbour es un módulo para Apache que permite correr tus PRGs directamente en la web!!!

Verificar si existe el archivo y lanzar

Postby Patricio Avalos Aguirre » Tue Jul 13, 2021 2:13 am

Estimados

como puedo saber si existe el archivo antes de lanzar el PDF

he tratado de buscar en la web pero no lo he podido lograr

Code: Select all  Expand view
BUTTON ID 'btnprint'  LABEL ' Print'  ACTION 'PrintPdf()' GRID 2 ICON '<i class="fas fa-home"></i>' CLASS 'btn-primary btnticket' OF o


Code: Select all  Expand view
<script>
               
                function PrintPdf() {
                  if existarchivo( 'cFileName.Pdf' )
                    window.open('cFileName.Pdf' );
                 }
 
Saludos
Patricio

__________________________________________________________________
Version: Harbour 3.2.0dev (r1307082134),Compiler: Borland C++ 5.8.2 (32-bit)
PCode version: 0.3, FWH 13.2
http://www.sialm.cl
User avatar
Patricio Avalos Aguirre
 
Posts: 1059
Joined: Fri Oct 07, 2005 1:56 pm
Location: La Serena, Chile

Re: Verificar si existe el archivo y lanzar

Postby Otto » Tue Jul 13, 2021 11:26 pm

Hello,
Please search for: javascript check file exists on server
I found: How do I check if file exists in jQuery or pure JavaScript?
https://stackoverflow.com/questions/364 ... javascript
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6047
Joined: Fri Oct 07, 2005 7:07 pm

Re: Verificar si existe el archivo y lanzar

Postby Otto » Tue Jul 13, 2021 11:53 pm

Code: Select all  Expand view


function main

TEMPLATE
<!DOCTYPE html>
<html>
<head>
</head>
<body>
   
    <h1>Test open PDF</h1>
    <button onclick="myFunction()">Open PDF</button>
   
    <script>
        function myFunction() {
            var url = "https://winhotel.space/modharbour_samples/test.pdf";

            if ( fileExists( url ) ){
            var myWindow = window.open("https://winhotel.space/modharbour_samples/test.pdf", "", "width=400,height=400");
            }else{
            alert("file not found");                
            }
               
        }
       
       
        function fileExists(url) {
            if(url){
                var req = new XMLHttpRequest();
                req.open('GET', url, false);
                req.send();
                return req.status==200;
            } else {
                return false;
            }
        }
       
    </script>
   
</body>
</html>

ENDTEXT

return
 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6047
Joined: Fri Oct 07, 2005 7:07 pm

RESUELTO Re: Verificar si existe el archivo y lanzar

Postby Patricio Avalos Aguirre » Wed Jul 14, 2021 2:57 am

Gracias Otto

FUNCIONO!!!
Saludos
Patricio

__________________________________________________________________
Version: Harbour 3.2.0dev (r1307082134),Compiler: Borland C++ 5.8.2 (32-bit)
PCode version: 0.3, FWH 13.2
http://www.sialm.cl
User avatar
Patricio Avalos Aguirre
 
Posts: 1059
Joined: Fri Oct 07, 2005 1:56 pm
Location: La Serena, Chile


Return to mod_harbour

Who is online

Users browsing this forum: No registered users and 1 guest