PHP - Mkdir Is Not Working
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); Similar TutorialsHello, 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 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 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 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. 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."; } ?> 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); } 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. 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? 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. 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 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. 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); 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!! 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 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. Hi, I've written a script for a client which creates a folder on the server using mkdir. The client wanted this folder to be created for them (don't ask why, it's complicated!), then they wanted to be able to FTP in and add files into the folder using FTP. The problem is that the script creates the file with a group of 99. When the client tries to FTP in and add their files, they get the following error: '550 Can't create directory: Permission denied', presumably because they're in a different group. What I need to be able to do is get the script to create a folder with a different group, so that my client can FTP their files into it. I thought I would be able to use PHP's chgrp after mkdir, as follows: mkdir($filepath, 0777) chgrp($filepath, 501); However then I get "Warning: chgrp() [function.chgrp]: Operation not permitted". I realise from reading the manual that I need to be a superuser to do this, which my web script obviously isn't. My question is, how can I get around this? Is there some setting in Apache that I can set? Thanks in advance for any help! Willo I've got a php script creating directories but it seems when I open them it says 'Failed to retrieve directory listing' within Filezilla as though the directory doesn't exist. I'm giving them the 0700 permission and in Filezilla if I give them 777 it still doesn't work. Am I doing something wrong or is this a limitation of somesort? // If directory does not exist, create it if (!is_dir($fullDirPath)){ mkdir($fullDirPath, 0700); } It's definitely there cauase I can see it and my code works with the files inside the directory but... just in FTP :/ Thanks! i dont understand what is wrong plz help me.
here is code
$name = "img/".rand(1,9999999).".png"; $myFile = $name; $fh = fopen($myFile, 'w') or die("can't open file"); $stringData = $html; fwrite($fh, $stringData); fclose($fh); $file=$name; $fst=file_get_contents($file); $im=imagecreatefromstring($fst); imagefilter($im, IMG_FILTER_GRAYSCALE); imagefilter($im, IMG_FILTER_NEGATE); //Convert to Grey Scale for($i=0;$i<123;$i++){ for($j=0;$j<50;$j++){ $px=imagecolorat($im,$i,$j); if($px<0x303030){ imagesetpixel($im,$i,$j,0); }else{ imagesetpixel($im,$i,$j,0xffffff); } } } $database = unserialize(@file_get_contents("db.txt")); if($database === false) $database = array(); // modify the database if needed if($_SERVER['REQUEST_METHOD'] == 'POST'){ if($_POST['submit'] == 'Add') $database[$_POST['ident']] = substr($_POST['letter'], 0, 1); if($_POST['submit'] == 'Del') unset($database[$_POST['ident']]); if($fh = @fopen('db111.txt', 'w+')){ fwrite($fh, serialize($database)); fclose($fh); } }else{ $newimage = true; } $width = 130; $height = 40; $captcha_gridstart =1; $captcha_gridspace =2; $letters = findletters($im, $width, $height, $captcha_gridstart, $captcha_gridspace); $count = count($letters); $cellw = ($count > 0) ? intval(100 / $count) : 0; //dispeckle the image and GET co-ordinates of the characters of captcha image and return them. function findletters($image, $width, $height, $gridstart, $gridspace){ $offsets = array(); $o = 0; $atstartx = true; for($x = 0; $x < $width; $x++){ $blankx = true; for($y = 0; $y < $height; $y++){ if(imagecolorat($image, $x, $y) == 0){ $blankx = false; break; } } if(!$blankx && $atstartx){ $offsets[$o]['startx'] = $x; $atstartx = !$atstartx; }else if($blankx && !$atstartx){ $offsets[$o]['endx'] = $x; $atstartx = !$atstartx; $o++; } } $count = $o; for($o = 0; $o < $count; $o++){ for($y = 0; $y < $height; $y++){ $blanky = true; for($x = $offsets[$o]['startx']; $x < $offsets[$o]['endx']; $x++){ if(imagecolorat($image, $x, $y) == 0){ $blanky = false; break; } } if(!$blanky){ $offsets[$o]['starty'] = $y; break; } } for($y = $height-1; $y > $offsets[$o]['starty']; $y--){ $blanky = true; for($x = $offsets[$o]['startx']; $x < $offsets[$o]['endx']; $x++){ if(imagecolorat($image, $x, $y) == 0){ $blanky = false; break; } } if(!$blanky){ $offsets[$o]['endy'] = $y; break; } } } for($o = 0; $o < $count; $o++){ $offsets[$o]['ident'] = ""; for($x = $offsets[$o]['startx'] + $gridstart; $x < $offsets[$o]['endx']; $x += $gridspace){ for($y = $offsets[$o]['starty'] + $gridstart; $y < $offsets[$o]['endy']; $y += $gridspace){ $offsets[$o]['ident'] .= ((imagecolorat($image, $x, $y) == 0) ? "0" : "1"); #echo $offsets[$o]['ident'].'<br>'; } } } return $offsets; } $a=""; foreach($letters as $letter){ $asciiletter = $database[$letter['ident']]; if(!empty($asciiletter)) { $a.=$asciiletter; } } |