Page 1 of 1

create folder / subfolder on the fly to store files

Posted: Fri Aug 19, 2011 7:19 pm
by inosent1
here is my code so far

Code: Select all

<?php
include("dbinfo.inc.php");


mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$term  = mysql_real_escape_string($_POST['term']);
$term2  = mysql_real_escape_string($_POST['term2']);

  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    //echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    //echo "Type: " . $_FILES["file"]["type"] . "<br />";
    //echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    //echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("efiles/" . $term . "/" . $term2 . "/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "efiles/" . $term . "/" . $_FILES["file"]["name"]);
      //echo "Stored in: " . "efiles/" . $_FILES["file"]["name"];
      }
    }
  
echo $term;

?> 
<html><body>
<script type="text/javascript">

</script>
</body></html>



where you see 'term and 'term2' are from user inputs. the concept is to have the files uploaded to folders with the terms the user states, which may not be created yet, but if they are i dont want to create them, just check to see if the file, then, has been uploaded to that location, etc

any ideas are welcome

Re: create folder / subfolder on the fly to store files

Posted: Sat Aug 20, 2011 8:04 am
by phphelpme
Here is an example of creating a directory:

http://php.net/manual/en/function.mkdir.php

Best wishes

Re: create folder / subfolder on the fly to store files

Posted: Mon Aug 22, 2011 12:21 pm
by inosent1
thanks, i got it

Re: create folder / subfolder on the fly to store files

Posted: Mon Aug 22, 2011 3:32 pm
by califdon
Do you really want to allow users to create directories on your server?? Generally I would consider this a really really bad practice. A hacker could write a simple little script to create thousands of directories on your server, unless you have taken other precautions to prevent it.