{"id":312,"date":"2017-02-11T23:26:25","date_gmt":"2017-02-11T22:26:25","guid":{"rendered":"http:\/\/lab.fawno.com\/?p=312"},"modified":"2022-03-07T15:51:44","modified_gmt":"2022-03-07T14:51:44","slug":"","status":"publish","type":"post","link":"https:\/\/lab.fawno.com\/en\/2017\/02\/11\/comprobar-una-ruta-y-crearla-si-no-existe\/","title":{"rendered":"","raw":""},"content":{"rendered":"","protected":false,"raw":""},"excerpt":{"rendered":"","protected":false,"raw":""},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_editorskit_title_hidden":false,"_editorskit_reading_time":0,"_editorskit_typography_data":[],"_editorskit_blocks_typography":"","_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","_es_post_content":"\n
Por azares de la vida he tenido, tengo y tendr\u00e9 que crear muchos scripts que crean directorios. Y la verdad, es un royo controlar cada vez si el directorio existe y hay que crearlo con los permisos adecuados, as\u00ed que ah\u00ed va la funci\u00f3n:<\/p>\n\n\n\n
La funci\u00f3n es muy sencilla de usar, si se llama s\u00f3lo son la ruta path_check('example\/path');<\/span> entonces devolver\u00e1 true<\/em> o false<\/em> seg\u00fan exista la ruta o no.<\/p>\n\n\n\n Si se llama con el modo, aka permisos tipo UNIX, function path_check ($path, $mode = null) {\n if (!is_dir($path)) {\n if (!empty($mode)) {\n if (is_file($path)) {\n unlink($path);\n }\n return mkdir($path, $mode, true);\n }\n return false;\n } else {\n return true;\n }\n}<\/pre>\n\n\n\n
path_check('example\/path', 0777);<\/code><\/span>\u00a0se comprueba la ruta y si no existe se crea, si la ruta es un fichero, se borra y se crea. En este caso devolver\u00e1 true<\/em> si se ha creado y false<\/em> en caso de error.<\/p>\n","_es_post_name":"comprobar-una-ruta-y-crearla-si-no-existe","_es_post_excerpt":"","_es_post_title":"Comprobar una ruta y crearla si no existe","_en_post_content":"","_en_post_name":"","_en_post_excerpt":"","_en_post_title":"","edit_language":"en","footnotes":""},"categories":[5,3],"tags":[6],"class_list":["post-312","post","type-post","status-publish","format-standard","hentry","category-php","category-tips","tag-php"],"ninja_gutenberg_blocks_featured_media_urls":{"thumbnail":"","ninja_gutenberg_blocks_landscape_large":"","ninja_gutenberg_blocks_portrait_large":"","ninja_gutenberg_blocks_square_large":"","ninja_gutenberg_blocks_landscape":"","ninja_gutenberg_blocks_portrait":"","ninja_gutenberg_blocks_square":"","full":""},"_links":{"self":[{"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/posts\/312","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/comments?post=312"}],"version-history":[{"count":8,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/posts\/312\/revisions"}],"predecessor-version":[{"id":1869,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/posts\/312\/revisions\/1869"}],"wp:attachment":[{"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/media?parent=312"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/categories?post=312"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/tags?post=312"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}