RE: [PHP-DB] No data?
| From: | Brad | Date: | Thu, 26 Jul 2012 10:14:06 +0000 |
| Subject: | RE: [PHP-DB] No data? | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-48370@lists.php.net to get a copy of this message | ||
The sql query is sound. The tmp_file is created correctly and can be viewed live. It just
does't hit the database. :(
-----Original Message-----
From: tamouse mailing lists [mailto:tamouse.lists@gmail.com]
Sent: Thursday, July 26, 2012 5:52 AM
To: Brad
Cc: php-db@lists.php.net
Subject: Re: [PHP-DB] No data?
In reading over LOAD DATA ... in the mysql reference. it makes particular note of the fact that the
file it's reading must be completely world readable, including all paths to the file. In
checking just now, I notice that a file uploaded by php and placed in /tmp is only readable by the
server user (aka, www-data on some systems).
"For security reasons, when reading text files located on the server, the files must either
reside in the database directory or be readable by all."
<http://dev.mysql.com/doc/refman/5.1/en/load-data.html>
This tiny script shows what happens:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html><head><title>file upload example</title> <meta
http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head>
<body> <h1>file upload example</h1>
<h2>$_FILES</h2>
<pre>
<?php var_dump($_FILES); ?>
</pre>
<?php
if (count($_FILES)>0) {
$lscmd = 'ls -l '.$_FILES['userfile']['tmp_name'];
echo '<h2>ls -l tmp_name</h2>'.PHP_EOL;
echo '<pre>'.
$lscmd.'</pre>'.PHP_EOL;
}
?>
<form enctype="multipart/form-data" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" /> </form>
</body>
</html>
When a file is submitted, this is the output:
file upload example
$_FILES
array(1) {
["userfile"]=>
array(5) {
["name"]=>
string(15) "testfile.txt"
["type"]=>
string(10) "text/plain"
["tmp_name"]=>
string(14) "/tmp/phphxGoQm"
["error"]=>
int(0)
["size"]=>
int(4244)
}
}
ls -l tmp_name
-rw------- 1 www-data www-data 4244 Jul 26 04:41 /tmp/phphxGoQm
Send this file: <form stuff shows up here>