0

我正在尝试使用 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 很陌生。

4

1 回答 1

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');
于 2014-09-22T18:45:45.160 回答