thenewperson Posted November 4, 2009 Share Posted November 4, 2009 having problem with upload script. Trying to have uploaded files upload to the folder "/uploads/"their username"/"their file"". But every time i upload something the folder does not create when it does not exist. The code im using below <?php if(isset( $_GET['user'] ) && strlen( trim( $_GET['user'] ) ) > 0 ){ $user = trim( $_GET['user'] ) ; } else { ## handle blank username } if( ! ctype_alnum ( $user ) ){ ## do something if $user is not alphanumeric echo "incorrect username"; } $the_path = '/uploads/' ; $user_dir = $the_path . $user . '/private' ; if( ! is_dir ( $user_dir ) ){ # try to make the directory if( ! mkdir( $user_dir , 0755 ) ){ ### handle fact that directory not made... } } move_uploaded_file($_FILES["file"]["tmp_name"], "'$user_dir . $user . '/private/" . str_replace (" ", "",$_FILES["file"]["name"] . $file)); ?> Quote Link to comment https://forums.phpfreaks.com/topic/180332-solved-php-upload-problem/ Share on other sites More sharing options...
MadTechie Posted November 4, 2009 Share Posted November 4, 2009 You need to make BOTH folders, create the users folder THEN create the private folder inside Quote Link to comment https://forums.phpfreaks.com/topic/180332-solved-php-upload-problem/#findComment-951280 Share on other sites More sharing options...
thenewperson Posted November 4, 2009 Author Share Posted November 4, 2009 You need to make BOTH folders, create the users folder THEN create the private folder inside if i recall someone said mkdir will make the directorys if doesnt exist? I need the folders to create themselves on upload without doing it manually Quote Link to comment https://forums.phpfreaks.com/topic/180332-solved-php-upload-problem/#findComment-951299 Share on other sites More sharing options...
MadTechie Posted November 4, 2009 Share Posted November 4, 2009 Okay let me ask a question If i was a new user, I assume I have no folder or private folder So when you do mkdir('/uploads/MadTechie/private'); /uploads/MadTechie/private can not be created because /uploads/MadTechie doesn't exists so your need to create BOTH ie mkdir('/uploads/MadTechie'); mkdir('/uploads/MadTechie/private'); Quote Link to comment https://forums.phpfreaks.com/topic/180332-solved-php-upload-problem/#findComment-951351 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.