Domanda

I am trying to create a folder in PHP, by calling a value. Creating one works fine. But once I try calling the value instead and concatenating it with the existing folder, it won't work. I have tried several things.

For example, I want to be able to have someone type in a name for their folder in an input field, so that they may choose what will the name of the folder be. For example, they could write on the website "mypics", and when I access my ftp program, I would now see images/mypics/

As for the HTML portion, I have this (check the fiddle for the rest of it http://jsfiddle.net/GF6qk/ ):

<input type="text" id="folder" name="folder">

As for the PHP aspect, I have the following

<?php

// We're putting all our files in a directory called images.

// Desired folder structure


$folder = $_POST['folder'];

$dirPath = 'images/'.$folder;
$result = mkdir($dirPath, 0755);
if ($result == 1) {
    echo $dirPath . " has been created";
} else {
    echo $dirPath . " has NOT been created";
}


//$image_name = '';
$uploaddir = 'images';

// The posted data, for reference
$file = $_POST['value'];
$name = $_POST['name'];

// Get the mime
$getMime = explode('.', $name);
$mime = end($getMime);

// Separate out the data
$data = explode(',', $file);

// Encode it correctly
$encodedData = str_replace(' ','+',$data[1]);
$decodedData = base64_decode($encodedData);


?> 

I have also used this line (which was the original line I tried in the above code, which I then changed).

$dirPath = 'images/$folder';
È stato utile?

Soluzione

try this and it is working

$folder = $_POST['folder'];
$dirPath = 'images/'.$folder;
$result = mkdir($dirPath);

if ($result == '1') {

echo $dirPath . " has been created";

} else {
echo $dirPath . " has NOT been created";
}

<input type="text"  id="folder" name="folder">

Altri suggerimenti

Are you receiving any errors? If so, what are they? Does the "images" folder already exist? I tried your exact code, and it worked if the images folder already exists.....

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top