JSHINER Posted March 17, 2008 Share Posted March 17, 2008 $directory = HOME_DIR . 'folder/photos/'; function uploadFile($postName, $newName, $moveTo){ if(isset($_FILES[$postName]) && $_FILES[$postName]['name']){ $type = substr($_FILES[$postName]['name'], strrpos($_FILES[$postName]['name'], ".")); if(file_exists($moveTo.$newName.$type)){ $t = 1; $name = $newName.'_'.$t; while(file_exists($moveTo.$name.$type)){ $t++; $name = $newName.'_'.$t; } $newName = $name; } if(move_uploaded_file($_FILES[$postName]['tmp_name'], $moveTo.$newName.$type)){ return $newName.$type; }else{ return false; } }else{ return false; } } if(isset($_SESSION['uploaded'])){ $uploaded = $_SESSION['uploaded']; }else{ $uploaded = array(); } foreach($_FILES AS $k=>$f){ if(substr($k, 0, 4) == 'file'){ $newName = $_POST['id']; if(isset($_FILES[$k]['name']) && $_FILES[$k]['name']){ $upload = uploadFile($k, $newName, $directory); if(!$upload){ $errors[$k] = 'File could not be uploaded.'; }else{ $uploaded[] = $upload; } } } } If $id = 505 this currently uploads to "folder/photos/505.jpg" - how can I get it to upload to "folder/photos/505/505.jpg" , "folder/photos/505/505_1.jpg" ? Quote Link to comment https://forums.phpfreaks.com/topic/96578-uploading-files/ Share on other sites More sharing options...
BlueSkyIS Posted March 17, 2008 Share Posted March 17, 2008 if you're sure the file will always be prefix.suffix, you could explode the file name with '.' then put the parts back together again with _1 in there. Quote Link to comment https://forums.phpfreaks.com/topic/96578-uploading-files/#findComment-494294 Share on other sites More sharing options...
JSHINER Posted March 18, 2008 Author Share Posted March 18, 2008 I already have it adding _1 to the end of the file name. I need it to create a folder for the $id if a folder does not already exist, then put the files in that folder. Quote Link to comment https://forums.phpfreaks.com/topic/96578-uploading-files/#findComment-494831 Share on other sites More sharing options...
JSHINER Posted March 19, 2008 Author Share Posted March 19, 2008 I think maybe I didn't make sense in my first post. What I want is for the user to upload a photo, and there will be an id that they're uploading under. So if the page is "upload.php?id=550", and this is the first photo uploaded for that id, it will create a folder (/550/), then put the photo in there. Then if they upload a second photo, it will see there is a folder already, and will just put the photo in the 550 folder. Does that make sense? Quote Link to comment https://forums.phpfreaks.com/topic/96578-uploading-files/#findComment-495435 Share on other sites More sharing options...
JSHINER Posted March 19, 2008 Author Share Posted March 19, 2008 Is this super difficult or something? Should I search elsewhere for the solution? Quote Link to comment https://forums.phpfreaks.com/topic/96578-uploading-files/#findComment-495506 Share on other sites More sharing options...
JSHINER Posted March 19, 2008 Author Share Posted March 19, 2008 Are you guys ignoring me? ??? Quote Link to comment https://forums.phpfreaks.com/topic/96578-uploading-files/#findComment-495841 Share on other sites More sharing options...
JSHINER Posted March 20, 2008 Author Share Posted March 20, 2008 Could someone please at least tell me if this is possible, or just tell me to $*#& off if you're not going to help me Quote Link to comment https://forums.phpfreaks.com/topic/96578-uploading-files/#findComment-496661 Share on other sites More sharing options...
JSHINER Posted March 20, 2008 Author Share Posted March 20, 2008 You know, I used to love this place, but now I can't even get a response after 3 days? This isn't the phpfreaks I've come to know and love. What the hell is going on? Quote Link to comment https://forums.phpfreaks.com/topic/96578-uploading-files/#findComment-496886 Share on other sites More sharing options...
BlueSkyIS Posted March 20, 2008 Share Posted March 20, 2008 you're explaining what you want to do. what have you tried and how did it fail? maybe check out mkdir() Quote Link to comment https://forums.phpfreaks.com/topic/96578-uploading-files/#findComment-496908 Share on other sites More sharing options...
JSHINER Posted March 21, 2008 Author Share Posted March 21, 2008 I think I've got the mkdir() figured out: mkdir(HOME_DIR . 'folder/sub/' . $_POST['folder_name'], 0777); But how can I first do a check to see if that directory exists. If it does, no nothing, if not create it. Quote Link to comment https://forums.phpfreaks.com/topic/96578-uploading-files/#findComment-497461 Share on other sites More sharing options...
JSHINER Posted March 21, 2008 Author Share Posted March 21, 2008 *SOLVED* Quote Link to comment https://forums.phpfreaks.com/topic/96578-uploading-files/#findComment-497485 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.