我是PHP的新手程序员,我遇到了问题..
我尝试使用PHP将SQL转储文件(* .sql)上传到数据库,但发生错误..这里是我的代码:
<?php
$eror = false;
$folder = './upload/';
$file_type = array('sql');
$max_size = 1000000; // 1MB
if(isset($_POST['btnUpload'])){
//Mulai memorises data
$file_name = $_FILES['data_upload']['name'];
$file_size = $_FILES['data_upload']['size'];
//cari extensi file dengan menggunakan fungsi explode
$explode = explode('.',$file_name);
$extensi = $explode[count($explode)-1];
//check apakah type file sudah sesuai
if(!in_array($extensi,$file_type)){
$eror = true;
$pesan .= '- Type file yang anda upload tidak sesuai<br />';
}
if($file_size > $max_size){
$eror = true;
$pesan .= '- Ukuran file melebihi batas maximum<br />';
}
//check ukuran file apakah sudah sesuai
if($eror == true){
echo '<div id="eror">'.$pesan.'</div>';
}
else{
//mulai memproses upload file
if(move_uploaded_file($_FILES['data_upload']['tmp_name'], $folder.$file_name)){
//catat nama file ke database
$f = fopen($file_name,"r+");
$sqlFile = fread($f, filesize($file_name));
$sqlArray = explode(';',$sqlFile);
foreach ($sqlArray as $stmt) {
if (strlen($stmt)>3 && substr(ltrim($stmt),0,2)!='/*') {
$result = mysql_query($stmt);
if (!$result) {
$sqlErrorCode = mysql_errno();
$sqlErrorText = mysql_error();
$sqlStmt = $stmt;
break;
}
}
}
if ($sqlErrorCode == 0) {
echo "Script is executed succesfully!";
} else {
echo "An error occured during installation!<br/>";
echo "Error code: $sqlErrorCode<br/>";
echo "Error text: $sqlErrorText<br/>";
echo "Statement:<br/> $sqlStmt<br/>";
}
}
}
}
?>
它显示和错误如下:
Warning: fopen(test.sql): failed to open stream: No such file or directory in C:\xampp\htdocs\tampung\action_upload.php on line 36
Warning: filesize(): stat failed for test.sql in C:\xampp\htdocs\tampung\action_upload.php on line 37
Warning: fread() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\tampung\action_upload.php on line 37
Notice: Undefined variable: sqlErrorCode in C:\xampp\htdocs\tampung\action_upload.php on line 50
Script is executed succesfully!
你可以告诉我出了什么问题吗?
最好的问候
答案 0 :(得分:0)
您必须提供已移动文件的完整路径:
{{1}}