monkey_slap Posted February 3, 2010 Share Posted February 3, 2010 So I've got some simple code that is supposed to upload an image. I've never done an upload before, so I just went pretty much verbatim to this: http://www.tizag.com/phpT/fileupload.php I am creating my directories dynamically. The admin creates a new project, and it sets up sub directories to create a new page. I create it like this: function createDirectory($username) { $thisdir = getcwd(); $sourceCSS = "codes.css"; //var to copy over css $destCSS = $thisdir ."/$username/codes.css"; //dest of css $sourceIndex = "index.php"; //var to copy over index.php $destIndex = $thisdir ."/$username/index.php"; //dest of index.php if(mkdir($thisdir ."/$username", 0777) && mkdir($thisdir ."/$username/mnstrtv", 0777) && mkdir($thisdir ."/$username/images", 0777) && mkdir($thisdir ."/$username/fies", 0777) && copy($sourceCSS, $destCSS) && copy($sourceIndex, $destIndex)){ return true; } else{ return false; } } My upload.php looks like this: <?php $username = $_POST['username']; $uploaddir = "/$username"; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile); ?> And my form looks like this: <form enctype="multipart/form-data" action="mnstrtv/upload.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="10485760" /> <input type="file" name="userfile" /> <br> <input type="submit" value="Upload File" /> </form> And finally, here are the errors I'm receiving: Warning: move_uploaded_file(/Blue hills.jpg) [function.move-uploaded-file]: failed to open stream... Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpUNasCO' to '/Blue hills.jpg' in... And it says its bombing on line 9, which is my move_uploaded_file() call. I did a search and it said that I may not have read/write permissions (chmod 777 error? If so, I'm not sure how to change my settings...) but I thought in my mkdir() having "0777" set the permissions correctly. I can provide any more details as necessary. Any help would be appreciated. Link to comment https://forums.phpfreaks.com/topic/190800-permissions-error-when-uploading-to-dynamic-directory/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.