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

677
Views
PHP Crear directorio (Error: No existe tal archivo o directorio)?

Tengo un pequeño problema aquí con mi php en el que intento crear un directorio, pero cuando se ejecuta el código aparece el mensaje de error.

Advertencia: mkdir() [function.mkdir]: no existe tal archivo o directorio

¿Alguien puede darme alguna orientación sobre dónde me estoy equivocando aquí?

 <? function generateRandomString($length = 10) { $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } return $randomString; } $Key = generateRandomString(); if(is_dir("Server1/".$Key) === true){ header("Refresh:0"); } else { mkdir("Server1/".$Key); echo $Key; } ?>
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Según la documentación :

bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = false [, resource $context ]]] )

Debe establecer recursivo en verdadero:

recursivo

Permite la creación de directorios anidados especificados en la ruta.

Alternativamente, si espera que exista la ruta secundaria, es posible que desee verificar que su ruta sea correcta.

over 4 years ago · Santiago Trujillo Report

0

if(is_dir("Server1/".$Key) === true){ header("Refresh:0"); } else { mkdir("Server1/".$Key); echo $Key; }

La llamada a is_dir() falla cuando el directorio "Server1/".$Key no existe pero también falla cuando el directorio Server1 no existe.

Por otro lado, por defecto, mkdir() no crea los directorios intermedios cuando no existen. Si el directorio Server1 no existe, is_dir() devuelve FALSE y mkdir() falla con el mensaje de error "No existe tal archivo o directorio".

Tiene sentido porque para crear el directorio "Server1/".$Key primero debe ir al directorio "Server1/" y crear el subdirectorio $Key dentro de él.

Puede hacer que funcione pasando TRUE como el tercer argumento de mkdir() :

 mkdir("Server1/".$Key, 0777, TRUE);
over 4 years ago · Santiago Trujillo Report

0

Si su secuencia de comandos php está en el directorio "Servidor1", no desea usar "Servidor1" en mkdir ...

Solo usa mkdir($Clave);

over 4 years ago · Santiago Trujillo 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!