Jump to content

[SOLVED] PHP upload problem


thenewperson

Recommended Posts

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));
?>

Link to comment
https://forums.phpfreaks.com/topic/180332-solved-php-upload-problem/
Share on other sites

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');

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.