|
Title: using variable in uploads Post by: jamin84 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; } } Title: Re: using variable in uploads Post by: GrandSchtroumpf 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
Powered by SMF 1.1 RC2 |
SMF © 2001-2005, Lewis Media
Joomla Bridge by JoomlaHacks.com |