Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
Cómo configurar el conjunto de variables php en php y obtener nombres de archivo de la carpeta

¿Cómo obtengo una lista de todos los nombres de archivo de los archivos en C:\xampp\htdocs\dump\uploads en php varible ellos obtienen el valor de php varible en js

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Para pasar una variable de PHP a JS, primero debe saber que PHP se procesa en el lado del servidor; Sin embargo, JS se ejecuta en el lado del cliente; Entonces, una forma de enviar variables de PHP a JS es usar JSON

 <!-- In your file of PHP you have: --> <!-- some code of php to generate variable of all your files... --> <?php $files = ['dir1','file1.txt','img.jpg']; ?> <!DOCTYPE html> <html> <head> <title></title> </head> <body> <!-- here inside the same file you have your script js --> <script type="text/javascript"> // call your variable with format JSON var filesJSON = <?php echo "'".json_encode($files)."'"; ?>; console.log(JSON.parse(filesJSON)); //['dir1', 'file1.txt', 'img.jpg'] </script> </body> </html>
about 4 years ago · Juan Pablo Isaza Report

0

Del lado del servidor Lee los archivos.

 $files = []; if ($handle = opendir('.')) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { $files[] = $entry; } } closedir($handle); }

Renderice la página y haga eco de los archivos $ en la etiqueta del script. como abajo:

 <script type="text/javascript"> const files = JSON.parse(<?php echo "'".json_encode($files)."'"; ?>); console.log('myFiles', files); </script>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!