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
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'.

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.