Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.