Jump to content

Upload files in new created folder


norm188

Recommended Posts

I'm using the following code to create a folder from a text field and works fine.

I would like to upload 3 files in the created folder.

 

<?php

// set our absolute path to the directories will be created in:

$path = $_SERVER['DOCUMENT_ROOT'] . '/uploads/';

 

 

if (isset($_POST['create'])) {

// Grab our form Data

$dirName = isset($_POST['dirName'])?$_POST['dirName']:false;

 

// first validate the value:

if ($dirName !== false && preg_match('~([^A-Z0-9]+)~i', $dirName, $matches) === 0) {

// We have a valid directory:

if (!is_dir($path . $dirName)) {

// We are good to create this directory:

if (mkdir($path . $dirName, 0775)) {

$success = "Your directory has been created succesfully!<br /><br />";

}else {

$error = "Unable to create dir {$dirName}.";

}

}else {

$error = "Directory {$dirName} already exists.";

}

}else {

// Invalid data, htmlenttie them incase < > were used.

$dirName = htmlentities($dirName);

$error = "You have invalid values in {$dirName}.";

}

}

?>

<html>

<head><title>Make Directory</title></head>

<body>

<?php echo (isset($success)?"<h3>$success</h3>":""); ?>

<h2>Make Directory on Server</h2>

<?php echo (isset($error)?'<span style="color:red;">' . $error . '</span>':''); ?>

<form name="phpMkDIRForm" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">

Enter a Directory Name (Alpha-Numeric only): <input type="text" value="" name="dirName" /><br />

<input type="submit" name="create" value="Create Directory" />

</form>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/227994-upload-files-in-new-created-folder/
Share on other sites

What a joke is the forum i'll ask it on a real forum where you get help delete my account num nuts and block my ip address too

 

No, actually the joke is when 'people' like you come in here expecting someone to gleefully write code for them, test it, and post it free of charge, then whine like a little baby when it doesn't happen. And don't worry, the thread won't be deleted; it'll be left here so the whole world can see your little nuggets of 'wisdom'.

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.