...

View Full Version : Creating a directory



Hayes
11-24-2007, 06:17 PM
Hey, im new to php and I want to know how to create a directory. I tried with the code below but it just shows the error message:

Warning: mkdir() [function.mkdir]: No such file or directory in C:\xampp\htdocs\planetgay\upload.php on line 5
Could not make directory

Couple someone please point me in the right direction. My code is below.



<?php


// create directory
mkdir("tmp/stuff") or die ("Could not make directory");

?>


Thanks in advance
Danny

timgolding
11-24-2007, 07:46 PM
Have you checked you have write access to the parent directory?

Hayes
11-24-2007, 07:50 PM
i am running this on xampp. So the parent directory is the one the file is stored in?

timgolding
11-24-2007, 07:56 PM
tmp it seems like.

psykx
11-25-2007, 01:25 AM
on Linux (which it seems like your using judging by the error message), mkdir produces the error message No such file or directory when the parent folder doesn't exist.

try

mkdir("tmp/") or die ("Could not make directory");
mkdir("tmp/stuff") or die ("Could not make directory");

Inigoesdr
11-25-2007, 02:11 AM
on Linux (which it seems like your using judging by the error message)
"No such file or directory in C:\xampp\htdocs\planetgay\upload.php"
That looks like a Linux path to you?


mkdir produces the error message No such file or directory when the parent folder doesn't exist.
You get that error on ANY operating system when the parent directory doesn't exist.

Hayes
11-25-2007, 08:07 PM
thanks psykx it fixed that problem. Next thing i need help on i want it to make a folder depending on what is in the database 'id'.

I tried this but it didnt work.

mkdir("images/["id"]") or die ("Could not make directory");


Thanks

Inigoesdr
11-25-2007, 08:16 PM
Show the rest of your code. Where you select the ids and such.

Hayes
11-25-2007, 11:40 PM
Changed how i am doing it a bit now. Im going to create a folder with users username. My code so far is:


<?php
require_once('includes/Sentry.php');
$theSentry = new Sentry();
if (!$theSentry->checkLogin(2) ){ header("Location: cmsAdmin/login.php"); die(); }
?>
<?php

// Require the classes
require_once('includes/DbConnector.php');

// Create an object (instance) of the DbConnector and Validator
$connector = new DbConnector();

$getUser = $loginConnector->query("SELECT * FROM cmsusers WHERE user = '".$_SESSION['user']."');

// create directory
mkdir("images/('user')") or die ("Could not make directory");
?>

I am getting all the session information from sentry.php


<?php
////////////////////////////////////////////////////////////////////////////////////////
// Class: sentry
// Purpose: Control access to pages
///////////////////////////////////////////////////////////////////////////////////////
class sentry {

var $loggedin = false; // Boolean to store whether the user is logged in
var $userdata; // Array to contain user's data

function sentry(){
session_start();
header("Cache-control: private");
}

//======================================================================================
// Log out, destroy session
function logout(){
unset($this->userdata);
session_destroy();
return true;
}

//======================================================================================
// Log in, and either redirect to goodRedirect or badRedirect depending on success
function checkLogin($user = '',$pass = '',$group = 10,$goodRedirect = '',$badRedirect = ''){

// Include database and validation classes, and create objects
require_once('DbConnector.php');
require_once('Validator.php');
$validate = new Validator();
$loginConnector = new DbConnector();

// If user is already logged in then check credentials
if ($_SESSION['user'] && $_SESSION['pass']){

// Validate session data
if (!$validate->validateTextOnly($_SESSION['user'])){return false;}
if (!$validate->validateTextOnly($_SESSION['pass'])){return false;}

$getUser = $loginConnector->query("SELECT * FROM cmsusers WHERE user = '".$_SESSION['user']."' AND pass = '".$_SESSION['pass']."' AND thegroup <= ".$group.' AND enabled = 1');

if ($loginConnector->getNumRows($getUser) > 0){
// Existing user ok, continue
if ($goodRedirect != '') {
header("Location: ".$goodRedirect."?".strip_tags(session_id())) ;
}
return true;
}else{
// Existing user not ok, logout
$this->logout();
return false;
}

// User isn't logged in, check credentials
}else{
// Validate input
if (!$validate->validateTextOnly($user)){return false;}
if (!$validate->validateTextOnly($pass)){return false;}

// Look up user in DB
$getUser = $loginConnector->query("SELECT * FROM cmsusers WHERE user = '$user' AND pass = PASSWORD('$pass') AND thegroup <= $group AND enabled = 1");
$this->userdata = $loginConnector->fetchArray($getUser);

if ($loginConnector->getNumRows($getUser) > 0){
// Login OK, store session details
// Log in
$_SESSION["user"] = $user;
$_SESSION["pass"] = $this->userdata['pass'];
$_SESSION["thegroup"] = $this->userdata['thegroup'];

if ($goodRedirect) {
header("Location: ".$goodRedirect."?".strip_tags(session_id())) ;
}
return true;

}else{
// Login BAD
unset($this->userdata);
if ($badRedirect) {
header("Location: ".$badRedirect) ;
}
return false;
}
}
}
}
?>

The error message i get is:

Parse error: syntax error, unexpected T_STRING in C:\xampp\htdocs\planetgay\upload.php on line 17

can anyone help?
Thanks in advance

aWishResigned
11-26-2007, 12:20 AM
It seems you're missing a quotation on line 14 at the end of the SQL statement. Look at the code you just posted and the error should be apparent.

Hayes
11-26-2007, 11:48 AM
i cant see the error. Please help

Inigoesdr
11-26-2007, 08:49 PM
$getUser = $loginConnector->query("SELECT * FROM cmsusers WHERE user = '".$_SESSION['user']."'");

// create directory
mkdir("images/{$user}") or die ("Could not make directory");
Change $user to the variable you select from the database.

Hayes
11-26-2007, 10:27 PM
That seems to of fixed one problem the next one i have is i am getting this error message:
Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\planetgay\upload.php on line 14

The code is now like this:


<?php
require_once('includes/Sentry.php');
$theSentry = new Sentry();
if (!$theSentry->checkLogin(2) ){ header("Location: cmsAdmin/login.php"); die(); }
?>
<?php

// Require the classes
require_once('includes/DbConnector.php');

// Create an object (instance) of the DbConnector and Validator
$connector = new DbConnector();

$getUser = $loginConnector->query("SELECT * FROM cmsusers WHERE user = '".$_SESSION['user']."'");

// create directory
mkdir("images/{$getUser}") or die ("Could not make directory");
?>

Thanks for all the help

GJay
11-26-2007, 10:45 PM
try reading over your code, you're making a lot of sloppy mistakes. Take a look at what you call your variables, and then what you use when you re-use them- check they're the same.

PHP error messages might at a first glance look unintelligible, but they're really quite specific. The first thing to look for is the line number, in this case 14. Which line of the code you've posted is 14? It's really helpful for people looking at your code to know this. The rest of the error tells you what the problem is- you're trying to call the query() method on something that isn't an object- why would that be? is $loginConnector somehow not an object when you think it should be? *shift eyes up and left* oh. now you feel silly?

aedrin
11-26-2007, 10:46 PM
At least try to figure things out yourself. Don't just post the new issue. This is a very simple problem to debug.



$connector = new DbConnector();

$getUser = $loginConnector->

$connector vs. $loginConnector?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum