我试图用BLOB创建多个上传。
以上代码给出了以下错误
警告:fopen(C:\ xampp \ tmp \ php4FC4.tmp):无法打开流:没有这样的文件或目录
PHP脚本
$jumlah_file = count($_FILES['userfile']['name']);
$path = pathinfo($_SERVER['PHP_SELF']);
for ($i = 0; $i < $jumlah_file; $i++)
{
$tmp_file = $_FILES['userfile']['tmp_name'][$i];
$filetype = $_FILES['userfile']['type'][$i];
$filesize = $_FILES['userfile']['size'][$i];
$filename = $_FILES['userfile']['name'][$i];
$destination = $path['dirname'].
'/data/'.$filename;
move_uploaded_file($tmp_file, $_SERVER['DOCUMENT_ROOT'].$destination);
}
$fp = fopen($tmp_file, 'r'); // ERROR LINE
$content = fread($fp, filesize($tmp_file));
$content = addslashes($content);
fclose($fp);
if (!get_magic_quotes_gpc())
{
$fileName = addslashes($filename);
}
$query = mysql_query("INSERT INTO `konveksi`.`foto` (`id_foto`, `id_daftar`, `id_pesanan`, `foto`) VALUES (NULL, '15', '1','$content');");
mysql_query($query) or die('Error, query failed');
我该怎么办?如果这是一个愚蠢的问题,请原谅我,我是PHP的新手。
答案 0 :(得分:0)
您已在move_uploaded_file($tmp_file, $_SERVER['DOCUMENT_ROOT'].$destination);
之前使用$fp = fopen($tmp_file, 'r');
移动了文件。之后文件位于其他位置。
正确的代码是:
$jumlah_file = count($_FILES['userfile']['name']);
$path = pathinfo($_SERVER['PHP_SELF']);
for ($i = 0; $i < $jumlah_file; $i++)
{
$tmp_file = $_FILES['userfile']['tmp_name'][$i];
$filetype = $_FILES['userfile']['type'][$i];
$filesize = $_FILES['userfile']['size'][$i];
$filename = $_FILES['userfile']['name'][$i];
$destination = $path['dirname'].
'/data/'.$filename;
$fp = fopen($tmp_file, 'r');
$content = fread($fp, filesize($tmp_file));
$content = addslashes($content);
fclose($fp);
move_uploaded_file($tmp_file, $_SERVER['DOCUMENT_ROOT'].$destination);
}
if (!get_magic_quotes_gpc())
{
$fileName = addslashes($filename);
}
$query = mysql_query("INSERT INTO `konveksi`.`foto` (`id_foto`, `id_daftar`, `id_pesanan`, `foto`) VALUES (NULL, '15', '1','$content');");
mysql_query($query) or die('Error, query failed');