PHP Classes

File must be in the database directory or be readable by all

Recommend this page to a friend!

      Quick CSV import  >  All threads  >  File must be in the database...  >  (Un) Subscribe thread alerts  
Subject:File must be in the database...
Summary:How to fix
Messages:5
Author:Alexander Skakunov
Date:2007-04-04 09:51:46
Update:2013-09-29 14:41:58
 

  1. File must be in the database...   Reply   Report abuse  
Picture of Alexander Skakunov Alexander Skakunov - 2007-04-04 09:51:47
Many users report that they get this error message:

"The file '/tmp/phpQtLp3j' must be in the database directory or be readable by all"

Your MySQL server cannot access the file. To fix that try:

1. To tune permissions to that folder, for example try (of course if you use Linux) to "chmod" the temp folder by 755 permissions or something like that. If you get 'permission denied for chmod', you are on the right way - just use the root account to do that.

2. If that doesn't help, you will have to copy the file to the mysql data
directory (format like "/[mysql installation path]/data/[database
name]/") and feed my script with this new filename.

The file is that CSV file you want to import to your database.

"To copy it" means that you have to change the code a little - call
copy() function to copy a temporary file (which is created when you
select a file to upload and press Submit) to mysql data directory.

"To feed it to the script" means that you have to set the 'file_name'
option not by the temporary file name, but by the name of file in
mysql data directory (for security reasons you faced).

To sum up:

WAS:
$csv->file_name = $_POST['file_source']['tmp_name'];

I SUGGEST TO DO:
$new_name = '/mysql/data/some_new_name.csv';
copy($_POST['file_source']['tmp_name'], $new_name); //copy!
$csv->file_name = $new_name; //feed to script!

Hope it helps :] If not - don't hesitate to write me back.

  2. Re: File must be in the database...   Reply   Report abuse  
Picture of patilpratap patilpratap - 2008-03-21 12:38:50 - In reply to message 1 from Alexander Skakunov
It is not working. Give me solution for that

  3. Re: File must be in the database...   Reply   Report abuse  
Picture of Davide Davide - 2008-06-18 13:35:00 - In reply to message 2 from patilpratap
Hi all,
I fixed by:

unlink("/tmp/new.csv");
$new_name = '/tmp/new.csv';
copy($_FILES['file_source']['tmp_name'], $new_name); //copy!
chmod("$new_name",0777);
$csv->file_name = $new_name; //feed to script!

all works weel now.

Thanks for the class!

Davide

  4. Re: File must be in the database...   Reply   Report abuse  
Picture of joel joel - 2010-06-12 07:39:32 - In reply to message 1 from Alexander Skakunov
Thanks Alexander,

Your script works well on my server

Thanks

Joel

  5. Re: File must be in the database...   Reply   Report abuse  
Picture of ariell david ariell david - 2013-09-29 14:41:58 - In reply to message 4 from joel
Hey there,

you don't need ANY script at all to solve this problem. Instead, the logical approach is to use SQL itself. Also, it's not a good idea to invoke UNIX commands thru PHP. What if you run into a situation, where the "php user" is prevented from running certain actions on a "bullet-proof" server?

In short English, add the "LOCAL" directive to you SQL, and done:
Like this: "LOAD DATA LOCAL INFILE..."

Make sure you provide the entire (absolute) path to your file - problem solved.

Best to all,
ariell