Question

i'm trying to make a new folder using php and html form using path : uploads/$loggedInUser->username$actfolder but no success and i want to delete it aswel :

php

<?php
include("db-settings.php");
include("config.php");
$foldername = $_POST['foldername'];

$path = "uploads/$loggedInUser->username
" . $foldername;
mkdir($path);
header('Location:myfiles.php')
?>

html

<form action="mkdir.php" method="post">
<input type="text name="foldername" id="foldername">
<input type="submit" value="submit">
</form>
Was it helpful?

Solution

Get rid of the line break.

$path = 'uploads/' . $loggedInUser->username . '/' . $foldername;

If that doesn't work, you are likely having a permissions problem.

Also, your approach is completely insecure! Anyone can post ../ in their username and put a directory wherever they want in your file system.

Finally, when you specify a Location: header, you must use a full URL. Most browsers will accept a relative resource like you have, but not all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top