PHP - Php Mkdir Subdirectories
I have problem creating multiple sub-directories inside a single directory using mkdir:
mkdir("files/".$lname,0777); mkdir("files/".$lname."/CV",0777); The above command works fine and creates the directory under $last name as files/$lname/CV. But I am unable to create further sub-directories inside $lname. For eg: mkdir("files/".$lname."/Cover", 0777); (This does not create the directory Cover) this is how my code snippet looks like if($result) { mkdir("files/".$lname,0777); mkdir("files/".$lname."/CV",0777); mkdir("files/".$lname."/Cover", 0777); mkdir("files/".$lname."/LOR", 0777); } Similar TutorialsIn the MySQL help forum someone asked how to list out all the files in a directory. Another person gave the following code: Code: [Select] <?php $handle = opendir('PUT NAME OF YOUR DIR HERE'); while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { echo $file,'<br />'; } } closedir($handle); ?> I found this to be very helpful! However, is there a way to modify it so that if there are subdirectories, it will list those as hyperlinks so the code would run off of the subdirectory if you were to click that link? When I asked that question in the MySQL forum, I was told that it had nothing to do with PHP which I know. So that's why I am posting it here. Can anyone help? Hi! I need a "very simple" PHP script which can compress a directory and all its multi-(infinite)level sub-directories using with .tar and .gz I have tried many complex scripts so far which don't work as most of them use ZIP and I don't have access to ZIP And a few of the simple ones, just don't function. Please help! Thank you ! - Xeirus. Hi I'm working with the following code to count the number of files in a directory, however, it doesn't seem to count files in subdirectories, does anyone have any ideas how I can get it to? Thanks! The code so far is as follows: <?php function numFilesInDir($directory, $includeDirs = false) { $files = glob($directory.'/*'); if($files === false) { user_error(__FUNCTION__."(): Invalid directory ($directory)"); return false; } $numFiles = count($files); if(!$includeDirs) //remove ! to count folders instead of files { $dirs = glob($directory.'/*', GLOB_ONLYDIR); $numFiles = $numFiles - count($dirs); } return $numFiles; } $numFiles = numFilesInDir('../media/Images'); if($numFiles === false) { echo "<p>Oops....something went wrong.</p>\n"; } else { echo "<p>There are $numFiles pictures in the Image folder.</p>\n"; } ?> Hello, I was wondering if it was possible to do mkdir() on a windows server, I know it is so I'm going to continue asking my question. I've to make a form, with the action as 'something.php' for example. The 'something.php' file has this in it '$name = $_POST['filename'];''. I was wondering if it was possible to get what was imputted in the form that I did in HTML, to make a file in 'C:\thirdir\$name'. That probably doesn't make any sence, if you get it you're a legend. Hi, I want to create a directory named according to the users ID which is auto incrementing. I want to a create the directory only if they have successfully registered. In more clear words the directory should be as 1 2 3 onwards. A bit of guidance would be appreciated with the mkdir function and how can i get the user ID exactly after they have registered before they sign in is this possible? Hi. I'm trying to create a directory folder on my server. I am using the following code, but keep getting an error? The images folder is set to 0777 on the server, and the file is located just outside the images folder. Code: [Select] $uID = $new_user->id; mkdir('/images/'.$uID.'/main/thumb', 0777, true); mkdir('/images/'.$uID.'/main/large', 0777, true); Error: Warning: mkdir() [function.mkdir]: Permission denied in /home/p/o/powtest/web/public_html/test_users.php on line 19 Warning: mkdir() [function.mkdir]: Permission denied in /home/p/o/powtest/web/public_html/test_users.php on line 20 Thanks for your help Hi I am running a linux web server and I am trying to use the mkdir function, for somereason I keep getting an error when I try run: // $clanid is set above mkdir('clans/' . $clanid . '/'); I receive the error: Code: [Select] Warning: mkdir() [function.mkdir]: No such file or directory in /home/kdmrhos1/public_html/ClanFind/register.php on line 253 I am running php 5.3.2 on Win Server 2008 R2 (IIS 7). When I execute the mkdir() function and pass it a string (i.e., the path) longer than 256 characters, it throws an error indicating "result too large". My question is whether this is because the mkdir() function cannot handle a string larger than 256 char or if it is a Windows issue on max characters allowed (path length). Any feedback or recommendations will be appreciated. Hi, I wonder whether someone may be able to help me please. I'm fairly new to PHP so please bear with me. I'm trying to put together a script which bascially creates a hierarchical tree of folders upon a new account being created by a user. I would like to take the 'username' that the user registers with to use as the name for the first folder, then, create a folder at the second level called 'images' and then finally, a folder within that called 'thumbs'. From the research that I've done, I believe that I need to use the 'mkdir' command, but I can't find a very straight forward tutorial. I just wondered whether someone could perhaps please help me out with this, so that I at least have a good solid starting point. Hey, I'm currently making a little script which I often get a string like = "images/folder/something/maybeanotherone/file.ext" so I'm interresting to know how could I create every directory in the correct order and the numbers of sub-directory isn't fix, so if anybody can give me an hint, I would appreciate =D Btw, tell me if I'm you don't understand what I mean, English isn't my primary language. I'm doing a flash app where i save webcam images to a folder on the server. I'm able to make this work when running of xampp on my machine, I create the required folder structure and I'm able to read from that folder and display the images, however once i move the stuff onto a live server, it fails to create the folders and it seems to be a permission problem. Is it server specific? i've tried chmod etc but I don't think i'm doing it right. any help, pointers for a non php developer would be most helpful. here's my code snippet <?php //This project is done by vamapaull: http://blog.vamapaull.com/ //The php code is done with some help from Mihai Bojin: http://www.mihaibojin.com/ $uid = $_GET[uid]; $structure = './images/' . date("Ymd") .'/' . $uid. '/'; // To create the nested structure, the $recursive parameter // to mkdir() must be specified. if(is_dir($structure)) { echo "Exists!"; } else { echo "Doesn't exist" ; if (!mkdir($structure,'0777', true) ) { die('Failed to create folders...'); } } if(isset($GLOBALS["HTTP_RAW_POST_DATA"])){ $jpg = $GLOBALS["HTTP_RAW_POST_DATA"]; $img = $_GET["img"]; $filename = 'images/' . date("Ymd"). "/" .$uid. "/img_". mktime(). ".jpg"; file_put_contents($filename, $jpg); } else{ echo "Encoded JPEG information not received."; } ?> Hi, I want to create a folder for every auto incrementing row so I used this $id=mysql_insert_id(); mkdir("../Setting/time/".$id); I am getting an error Warning: mkdir() [function.mkdir]: No such file or directory in C:\xampp\htdocs\Setting\time\index.php I have used the mkdir function in this similar method before there was no problem. For some reason it is not working now. If I just try it on a blank page example the following method seems to work could some one point to me what I might be doing wrong? $tid=1; mkdir("../Setting/time/".$tid); Okay I finally got some bugs worked out, but after further testing I found new bugs. The variables $loggedinid and $pid are working. I am receiving the following error: "An error occured: Warning: mkdir() [function.mkdir]: No such file or directory in D:\Hosting\5366560\html\file_upload\server\script.php on line 131" Now when I go to line 131 in script.php mkdir("../uploads/$loggedinid/$pid", 0777); What should my next step be? I am not sure where to start. Adam I am trying to create a folder using amfphp using this method: <?php function createProject($dir) { $query = mysql_query("SELECT * FROM projects WHERE proj_path = '$dir'"); $num = mysql_num_rows($query); if ($num > 0) { return "folder already exists"; } else { $root = $_SERVER['DOCUMENT_ROOT']; $theDir = $root . $this->dataFolder . "/" . $dir; //return $theDir; -> "/home/content/c/s/8/cs8xo/html/xxxxxxx/project_data/testfolder2" return mkdir($theDir,0755); } } ?> I've commented out what $theDir returns when I pass it a $dir. $this->dataFolder == "/xxxxxxx/project_data" When I return the mkdir(), I get this error: Code: [Select] (Object)#0 message = "faultCode:AMFPHP_RUNTIME_ERROR faultString:'mkdir(): No such file or directory' faultDetail:'/home/content/c/s/8/cs8xo/html/xxxxxxx/amfphp/services/clientlogin2/Projects.php on line 147'" name = "Error" rootCause = (null) Line 147 is referring to the mkdir() line. Can anyone spot anything obvious that I could be missing? Hi I have a script Code: [Select] mkdir("myitems/images", 0777); chmod("myitems/images", 0777); if (!copy('downloads.zip', 'myitems/images/downloads.zip')) { echo "failed"; } when I run it, the folder is created and when checking folder permissions, it shows 777 but it fails on copying the file. if I manually create the folder "myitems/images/" and set it to 777, then when I run the script, the file is copied for some reason when I manually create the folder it works, but when PHP creates the folder, it fails on something any ideas? racking my brain trying to figure out why Please help. I am simply trying to create a directory if it doesn't already exist. I am working from one site (www.mysite.com/folder1/folder2/folder3/here). I want to have this PHP script make a directory on another one of my sites (www.mysite2.com/images) $dirname = "../../mysite2.com/images"; <--this is the root directory (www.mysite2.com/images) $filename = "/$sitest/$userid/"; <-- this is the folder we want to create if it doesn't already exist (www.mysite2.com/images/us/27) $fulldirname = "$dirname$filename"; <--this should be the total path (mysite2.com/images/us/27) if (file_exists($fulldirname)) { echo "The directory {$fulldirname} exists"; } else { mkdir($fulldirname, 0777); echo "The directory {$fulldirname} was successfully created."; } Hope someone can help me! I have an upload script that stores users files, it creates a dir using the users name which will store their uploads! The problem is because I am on a shared host with safe mode ON i get an error when trying to upload to that directory via a form, the error says something like SAFE MODE Restriction in effect. The script whose uid is 500 is not allowed to access /proc/uptime owned by uid 0 in ...... If I create a dir manually(FTP) it works fine! But I cannot obviously create a dir for each new user as the registration is automatic, so at the moment I have 1 common dir for all users to upload to, but this will eventually cause too much congestion and slow things down! Any ideas! Thanks!! Im in the process of setting up a social media site , Just switched from basic hosting to Dedicated Server Everything was working till i switched . I have a basic join forum and email activation , On the register.php file it tell script to make a directory mkdir into member/folder like this below, But it will make the folder for the id of that user but will not let them upload any images?. At first it wouldnt even make a folder but i found out it was a permissions issue with my server i fixed it , im guessing the upload is also a permission's issue ? But the script automaticly make the members/"$id" folder and i dont know how to set permission for auto create folder that if i even have to ? so confused. (BEGGGGINGG !! FORRRRR HELPPPPPPPPPPPPPPPPPPPP! Im running a dedicated server with godaddy, On centOs w/ Plesk Panel 9.3.0 ------------------------------------------------------------------------------------------- $id = mysql_insert_id(); // Create directory(folder) to hold each user's files(pics, MP3s, etc.) mkdir("members/$id", 0755); Hi, How do you create a folder in the main dir (public_html) when you are a few folders deep? My code... mkdir("../../../../../filestore/images/$page_id/", 0644); I seem to get an error each time failing to create the folder. Is there away to go direct to the public html folder? Thanks for any help. Pretty simple I would think but I'm unsure on the syntax. I have a variable, $ename. It's actually data from a form that I pass to said variable. What I want is to then in turn use this string in a mkdir() function. Something like Code: [Select] mkdir("dir/folder/$ename/"); Obviously that doesn't work. I'd imagine I have to use some sort of . syntax. |