not reading $_POST in one part of the script...

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
Flux
-


Joined: 13 Oct 2006
Posts: 48

PostPosted: Wed Feb 21, 2007 7:43 am    Post subject: not reading $_POST in one part of the script... Reply with quote

I have a form:
Code:
<form enctype="multipart/form-data" action="upload.php" method=post>
Upload a file:<br>
<input name="file" type="file"><br>
Subfolder(s) (Optional):<br>
<input name="folder" type="text"><br>
(Media is automatically arranged under the following categories: "music", "pics", "video", "other"; and subfolders are organized within those folders.)<br>
<input type="submit" value="Send File"></form>


and I have the upload code:
Code:
if ($_FILES['file']['size'] < 20971520)
  {
  if ($_FILES['file']['error'] > 0)
    {
    echo "Error: " . $_FILES['file']['error'] . "<br />";
    }
  else
    {
   if ((eregi(".php", $_FILES['file']['name'])) || (eregi(".aspx", $_FILES['file']['name'])) || (eregi(".asp", $_FILES['file']['name'])) || (eregi(".htm", $_FILES['file']['name'])) || (eregi(".html", $_FILES['file']['name'])) || (eregi(".jsp", $_FILES['file']['name'])) || (eregi(".cfm", $_FILES['file']['name'])) || (eregi(".vb", $_FILES['file']['name'])) || (eregi(".js", $_FILES['file']['name'])) || (eregi(".mht", $_FILES['file']['name'])) || (eregi(".cgi", $_FILES['file']['name']))) {
   die("Please upload in .txt format");
   }
   else {
   if (($_FILES['file']['type'] == "image/gif") OR ($_FILES['file']['type'] == "image/jpeg") OR ($_FILES['file']['type'] == "image/pjpeg") OR ($_FILES['file']['type'] == "image/png") OR ($_FILES['file']['type'] == "image/bmp") OR ($_FILES['file']['type'] == "image/x-emf")) {
   $medium = "pics";
   }
   elseif (($_FILES['file']['type'] == "audio/mpeg") OR ($_FILES['file']['type'] == "audio/x-ms-wma") OR ($_FILES['file']['type'] == "audio/wav")) {
   $medium = "music";
   }
   elseif (($_FILES['file']['type'] == "video/avi") OR ($_FILES['file']['type'] == "video/x-ms-wmv") OR ($_FILES['file']['type'] == "video/quicktime")) {
   $medium = "video";
   }
   else {
   $medium = "other";
   }
   if (!($_POST['folder'] = "")) {
      if (eregi('^/' , $_POST['folder'])) {
      $subfolder1 = substr($_POST['folder'] , 1);
      }
      else {
      $subfolder1 = $_POST['folder'];
      }
      if (!(eregi('/$' , $_POST['folder']))) {
      $subfolder2 = $subfolder1 . "/";
      }
      else {
      $subfolder2 = $subfolder1;
      }
      $subfolder = $subfolder2;
   }
   else {
      $subfolder = "";
   }
    if (file_exists("files/" . $_SESSION['s_username'] . "/" . $medium . "/" . $subfolder . $_FILES['file']['name']))
      {
      echo $_FILES["file"]["name"] . " already exists.  You should rename it.";
      }
   else
      {
      if (!(file_exists("files/" . $_SESSION['s_username'] . "/" . $medium . "/" . $subfolder))) {
         mkdir("files/" . $_SESSION['s_username'] . "/" . $medium . "/" . $subfolder); }

      move_uploaded_file($_FILES["file"]["tmp_name"],
      "files/" . $_SESSION['s_username'] . "/" . $medium . "/" . $subfolder . $_FILES['file']['name']);
     echo "Name: " . $_FILES['file']['name'] . "<br />";
      echo "Type: " . $_FILES['file']['type'] . "<br />";
      echo "Size: " . ($_FILES['file']['size'] / 1024) . " KB<br />";
      echo "Stored in: " . "/files/" . $_SESSION['s_username'] . "/" . $medium . "/" . $subfolder .  $_FILES['file']['name'];
     echo '<br><a href="/index.php" title="Main Page">Return to the Main Page</a>';
      }
    } }
  }
else
  {
  echo 'Your file is bigger than 20 MB.  Please use the <a href="_URL_" title="FTP Server">FTP Server</a> to upload the file.  If you don'."'".'t, the likelihood that the file will actually be uploaded depends on how good a connection there is between the server and your computer, which is not, likely, high enough.';
  }


See the form's 'folder' input?
and the $subdirectory part of the script?
I want to make that work.
My upload script automatically organizes uploads into one of four files: music, pics, video, or other; of a user's folder by alias.
so blah.jpg uploaded under username flux goes to:
/files/flux/pics/blah.jpg

But with the subdirectory I want to give my users the ability to add directories, like so:
username flux
file blah.jpg
subdirectory "etc/directory/"
which should cause the file to be saved under:
/files/flux/pics/etc/directory/blah.jpg

I've noticed after echoing $_POST['folder'] in various parts of my script that it reads fine immediately after saving the file, but it reads as " " otherwise. Anybody know why and how to fix it? Is it a php.ini thing..?

Thanks in advance.

Edit: Does anyone know...?...
_________________
My signature is so lame.

I think phpBB forums hates my laptop '.';
Back to top View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group