Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:

Password:

Remember me

using variable in uploads
Welcome, Guest. Please login or register.
December 02, 2008, 11:20:35 AM
11304 Posts in 1248 Topics by 498 Members
Latest Member: katCheeme
Experts Round Table Network  |  Serverside Technology  |  PHP  |  using variable in uploads « previous next »
Pages: [1]
Author Topic: using variable in uploads  (Read 515 times)
jamin84

Offline Offline

Posts: 4


« on: October 05, 2007, 03:24:34 PM »

The task is for multiple users to login to the system, and each upload 3 .pdf files to the server. I want to create separate folders within the uploads folder based on the unique userID using php. These folders don't exist before the user logs in, and they are named after the user ID that the user logs in with using mkdir(). The goal is to organize the pdf files by user. If they have logged in before, it recognizes this and skips the mkdir() call. The folder is created before the upload step no problem. The $id is constantly changing, and I just can't figure out how to get the code correct to make the uploads go to the newly created folder. It works when the "uploads/" folder is used by itself. Any thoughts?

$id = $_SESSION['id'];

   // 1. check to see if all pdfs
   foreach ($_FILES['userfiles']['type'] as $key => $type) {
      if($type != "application/pdf") {
         $error_pdf = true;
      }
   }
   // 2. if all pdf, then upload
   if ($error_pdf != true) {
      foreach ($_FILES["userfiles"]["error"] as $key => $error) {
         if ($error == UPLOAD_ERR_OK) {
            echo "$error_codes[$error]";
            $tmp_name = $_FILES["userfiles"]["tmp_name"][$key];
            $name = $_FILES["userfiles"]["name"][$key];
            $uploaddir = "uploads/".$id."/$name";
            move_uploaded_file($tmp_name, $uploaddir);
         }
         else $error_upload = true;
      }
   }
Logged
GrandSchtroumpf
Mentor

Offline Offline

Posts: 410



« Reply #1 on: October 06, 2007, 04:15:17 PM »

Check if the directory exists and if it's writable.
http://www.php.net/manual/en/function.is-dir.php
http://www.php.net/manual/en/function.is-writable.php
Logged
Pages: [1]
« previous next »
    Jump to: