Jump to content

Need php upload help again


thenewperson

Recommended Posts

Trying to have folder create based on username. So if the username Frank uploads something i want his file to be uploaded to folder uploads/frank/(his file here). But im not good with php and screwing up. I have the upload code already and had it working on uploading to certain folder but cant get it to create its own folder if it doesnt exist yet.

 

<?php
$uploaddir = './uploads/'; 
$file = $uploaddir . basename($_FILES['uploadfile']['name']); 
$size=$_FILES['uploadfile']['size'];
if($size>500*1024)
{
echo "error file size > 500 MB";
unlink($_FILES['uploadfile']['tmp_name']);
exit;
}
move_uploaded_file($_FILES["file"]["tmp_name"],
      "'.$_GET['username'].'/private/"  . str_replace (" ", "",$_FILES["file"]["name"] . $file));
?>

 

if you need to look at other code to just ask. Just trying to get it to create folder based on their username in directory "uploads/"their username"/theirfile. Upload there but if folder doesnt exist create it on their first upload. So if anyone could help plz do.

Link to comment
Share on other sites

you need to tell php to create the folder first take look at the example below

 

<?php
if(!is_dir("uploads/".$_GET['username'])){ mkdir("uploads/".$_GET['username']); }
?>

 

as the example above shows we check to make sure the directory dosnt exist and then create it,

 

<?php
$uploaddir = './uploads/'; 
$file = $uploaddir . basename($_FILES['uploadfile']['name']); 
$size=$_FILES['uploadfile']['size'];
if($size>500*1024)
{
echo "error file size > 500 MB";
unlink($_FILES['uploadfile']['tmp_name']);
exit;
}
if(!is_dir("uploads/".$_GET['username'])){ mkdir("uploads/".$_GET['username']); }
move_uploaded_file($_FILES["file"]["tmp_name"],
      "'.$_GET['username'].'/private/"  . str_replace (" ", "",$_FILES["file"]["name"] . $file));
?>

 

Stuie

 

Link to comment
Share on other sites

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.