For security concerns,
You want to upload a picture at the same time, in the image of the directory automatically generated a blank HTM file.
The picture catalog is defined by time, so the directory is a bit more.
How does PHP implement this?
Reply to discussion (solution)
Like this
if (!file_exists (' index.html ')) { file_put_contents (' index.html ', ' Hello World ');}
Touch (' index.html ')
Ecmall's:
function Ecm_mkdir ($absolute _path, $mode = 0777) { if (Is_dir ($absolute _path)) { return true; } $root _path = Root_path; $relative _path = Str_replace ($root _path, ", $absolute _path); $each _path = explode ('/', $relative _path); $cur _path = $root _path;//path of the current loop foreach ($each _path as $path) { if ($path) { $cur _ Path = $cur _path. '/' . $path; if (!is_dir ($cur _path)) { if (@mkdir ($cur _path, $mode)) { fclose (fopen ($cur _path. '/index.htm ', ' W ')); } else { return false ; }}}} return true;}
Like this
if (!file_exists (' index.html ')) { file_put_contents (' index.html ', ' Hello World ');}
Create location how to set
Should be set to a picture all paths are automatically generated HTML files
The patch address is file/2015/05/20/100.gif.
That should be in the file directory 2015 directory 05 directory and 20 directories are generated a blank HTML file do not know how to achieve AH
$IMGURL = '/file/2015/05/20/100.gif '; $path = DirName ($IMGURL); createhtml ($path); function createhtml ($path) {if (!file _exists ($path. '/index.html ') { file_put_contents ($path. '/index.html ', ' Hello World '); Createhtml (DirName ($path));}
$IMGURL = '/file/2015/05/20/100.gif '; $path = DirName ($IMGURL); createhtml ($path); function createhtml ($path) {if (!file _exists ($path. '/index.html ') { file_put_contents ($path. '/index.html ', ' Hello World '); Createhtml (DirName ($path));}
You change it yourself, this recursion does not determine the exit condition
$IMGURL = '/file/2015/05/20/100.gif '; $path = DirName ($IMGURL); createhtml ($path); function createhtml ($path) {if (!file _exists ($path. '/index.html ') { file_put_contents ($path. '/index.html ', ' Hello World '); Createhtml (DirName ($path));}
Generate files only in/file/2015/05/20/
I actually wrote 3 things, and now the question is how to merge the code.
$file _path = ' file/';
$tm _path = ' file/'. $Y. '/'; file/2015
$path = ' file/'. $Y. '/'. $M. '/'; File/2015/05
File_put_contents ($path. '/index.html ', ' 111 ');
File_put_contents ($tm _path. '/index.html ', ' 111 ');
File_put_contents ($file _path. '/index.html ', ' 111 ');
want to upload images in the same time, in the image of the directory automatically generated a blank HTM file
Obviously the picture file has been saved, assuming that the path to save the picture is in the $img _path
Then just
File_put_contents (dirname ($img _path). '/index.html ', ');
If you are not sure if the directory exists when you save the picture, then this is OK.
@mkdir (dirname ($img _path), 0666, true);
want to upload images in the same time, in the image of the directory automatically generated a blank HTM file
Obviously the picture file has been saved, assuming that the path to save the picture is in the $img _path
Then just
File_put_contents (dirname ($img _path). '/index.html ', ');
If you are not sure if the directory exists when you save the picture, then this is OK.
@mkdir (dirname ($img _path), 0666, true);
The directory for all paths must have an HTML file