0

I need that data which be taken from mySQL table, be used as part a directory of saving path.

The code is:

<?php
$dbconnection = mysql_connect('localhost', 'root', '');
if(!$dbconnection)
{
die('Login error: ' . mysql_error());
} 
$fold_path = mysql_result(mysql_query("SELECT fold_path FROM clients WHERE id = 16"),0);
mysql_close($dbconnection);
$uploaddir = getcwd().DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR.$fold_path.DIRECTORY_SEPARATOR;
$uploadfile = $uploaddir.basename($_FILES['file']['name']);
if(!is_dir($uploaddir)) mkdir($uploaddir) ;
move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile);
?>

fold_path field got a type: varchar(100)

When i trying to save file, its ignoring variable, taken from table and determine its as null.

Here is debug information, when i try to use different ways.

Output $fold_path through echo: directory

Output $uploaddir through echo: ..\mydomain\upload\directory\

Output $fold_path in text file through fwrite: // here is null

Output $uploaddir in text file through fwrite: ..\mydomain\upload\\

6
  • Please show us what sort of data you have in your clients table Commented Jun 22, 2015 at 11:40
  • id as int(11), key, unique; login as varchar(255), unique; password as varchar (100); salt as varchar (100); fold_path asvarchar (100); date as timestamp, current_timestamp; Encode: utf8_general_ci Commented Jun 22, 2015 at 11:43
  • Maybe I am missing it but I cannot see any use of fwrite here, also after you mkdir you may want to see if it returns true to a file_exists call Commented Jun 22, 2015 at 13:01
  • i used fwrite for debug, its not necessary at final code. About mkdir i agreed with you, but at current moment im prioritize fixing a "path receive code". Commented Jun 22, 2015 at 13:09
  • Can you try this and tell me if it creates the directory you want? gist.github.com/catharsisjelly/c16d6fdc73f4e7306491 Commented Jun 22, 2015 at 13:42

1 Answer 1

0

Problem solved, i just forgot to plug in database

$dbconnection = mysql_connect('localhost', 'root', '');
if(!$dbconnection)
{
die('Ошибка соединения: ' . mysql_error());
}
mysql_select_db('database', $dbconnection) or die('Could not select database.');
Sign up to request clarification or add additional context in comments.

1 Comment

That will do it, I was going to narrow it down if it was your DB or not (that was the idea behind my test

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.