Experts Round Table Network
Navigate
Home
ArticleWiki
Forum
Journal
Search
Newsletter
Links
Tech News
expertsrt.com
Welcome Guest.
Username:
Password:
Remember me
Forgot your password?
Register
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
Home
Help
Search
Login
Register
Experts Round Table Network
|
Serverside Technology
|
PHP
|
using variable in uploads
« previous
next »
Pages:
[
1
]
Print
Author
Topic: using variable in uploads (Read 515 times)
jamin84
Offline
Posts: 4
using variable in uploads
«
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
Posts: 410
Re: using variable in uploads
«
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
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
ERT 1.5
-----------------------------
=> Round Table Learning Center
=> Bug reports
-----------------------------
Legacy
-----------------------------
=> The next level
=> History of ERT
-----------------------------
Community Affairs
-----------------------------
=> Introductions
=> Ballot Box
===> Closed Polls
=> Soapbox
=> Propose and Consult
===> Propose and Consult...CLOSED
-----------------------------
Bits and Bytes
-----------------------------
=> Tips, Tricks, Snippets, Tidbits And General Pearls Of Wisdom
-----------------------------
Serverside Technology
-----------------------------
=> PHP
=> ASP
-----------------------------
Webservers
-----------------------------
=> Apache
=> IIS
-----------------------------
Databases
-----------------------------
=> MySQL
=> Access
=> MS SQL Server
-----------------------------
Clientside Technology
-----------------------------
=> HTML
=> CSS
=> Javascript
=> Flash
=> WAP/WML
-----------------------------
Web Technologies
-----------------------------
=> General Web Dev
=> Web Standards
=> XML
=> Online Marketing
-----------------------------
Graphics
-----------------------------
=> Graphics Design and Animation
-----------------------------
Programming
-----------------------------
=> .NET
=> JAVA
=> MS DOS Batch Scripting
=> Mathematics
=> C & C++
=> VB
=> Delphi
=> Algorithm design
-----------------------------
Operating Systems
-----------------------------
=> Windows (General)
=> NT Based (2K, 2K-03, NT, XP, Vista)
=> Open Source (All)
-----------------------------
Hardware
-----------------------------
=> Hardware General
=> Gamers Hardware (Advanced)
-----------------------------
Networking
-----------------------------
=> Home (small)
=> Office (large)
=> Internet
-----------------------------
Security
-----------------------------
=> General Security Issues
-----------------------------
Rants/Opinions/Proposals
-----------------------------
=> Site operation
Powered by SMF 1.1 RC2
|
SMF © 2001-2005, Lewis Media
Joomla Bridge by
JoomlaHacks.com