PHP - Changing The Group Of A Folder Created By Php (using Mkdir)
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 Similar TutorialsHi 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 I'm using the following code to create a folder from a text field and works fine. I would like to upload 3 files in the created folder. <?php // set our absolute path to the directories will be created in: $path = $_SERVER['DOCUMENT_ROOT'] . '/uploads/'; if (isset($_POST['create'])) { // Grab our form Data $dirName = isset($_POST['dirName'])?$_POST['dirName']:false; // first validate the value: if ($dirName !== false && preg_match('~([^A-Z0-9]+)~i', $dirName, $matches) === 0) { // We have a valid directory: if (!is_dir($path . $dirName)) { // We are good to create this directory: if (mkdir($path . $dirName, 0775)) { $success = "Your directory has been created succesfully!<br /><br />"; }else { $error = "Unable to create dir {$dirName}."; } }else { $error = "Directory {$dirName} already exists."; } }else { // Invalid data, htmlenttie them incase < > were used. $dirName = htmlentities($dirName); $error = "You have invalid values in {$dirName}."; } } ?> <html> <head><title>Make Directory</title></head> <body> <?php echo (isset($success)?"<h3>$success</h3>":""); ?> <h2>Make Directory on Server</h2> <?php echo (isset($error)?'<span style="color:red;">' . $error . '</span>':''); ?> <form name="phpMkDIRForm" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Enter a Directory Name (Alpha-Numeric only): <input type="text" value="" name="dirName" /><br /> <input type="submit" name="create" value="Create Directory" /> </form> </body> </html> I am using apache web server on linux. I am using php for coding. My php code is not able to read the files from /var/tmp folder. If apache itself creates some files in /var/tmp folder then php code is able to read it. Why this permission denied issues are there though full access permissions are given to each file?
I got this script: But it give me error, file_get_contents cannot open stream. I need to add the FTP connection with user/pass paramaters. then look in set http url, to get the file contents(images) and transfer to ftp server location. Can Anyone take alook and tell me if I am going down the right path and how to get there. Please Code: [Select] function postToHost($host, $port, $path, $postdata = array(), $filedata = array()) { $data = ""; $boundary = "---------------------".substr(md5(rand(0,32000)),0,10); $fp = fsockopen($host, $port); fputs($fp, "POST $path HTTP/1.0\n"); fputs($fp, "Host: $host\n"); fputs($fp, "Content-type: multipart/form-data; boundary=".$boundary."\n"); // Ab dieser Stelle sammeln wir erstmal alle Daten in einem String // Sammeln der POST Daten foreach($postdata as $key => $val){ $data .= "--$boundary\n"; $data .= "Content-Disposition: form-data; name=\"".$key."\"\n\n".$val."\n"; } // Sammeln der FILE Daten if($filedata) { $data .= "--$boundary\n"; $data .= "Content-Disposition: form-data; name=\"".$filedata['name']."\"; filename=\"".$filedata['name']."\"\n"; $data .= "Content-Type: ".$filedata['type']."\n"; $data .= "Content-Transfer-Encoding: binary\n\n"; $data .= $filedata['data']."\n"; $data .= "--$boundary--\n"; } // Senden aller Informationen fputs($fp, "Content-length: ".strlen($data)."\n\n"); fputs($fp, $data); // Auslesen der Antwort while(!feof($fp)) { $res .= fread($fp, 1); } fclose($fp); return $res; } $postdata = array('var1'=>'today', 'var2'=>'yesterday'); $filedata = array( 'type' => 'image/png', 'data' => file_get_contents('http://xxx/tdr-images/images/mapping/dynamic/deals/spot_map') ); echo '<pre>'.postToHost ("localhost", 80, "/test3.php", $postdata, $filedata).'</pre>'; 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 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 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."; } ?> 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 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. 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, 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); 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? 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, 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. 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!! 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."; } 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); |