Georg-71
17.01.2011 - 19:18
<?php
include './blocks/db.php'; /*Соединяемся с базой*/
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Обработчик</title>
<link href="template.css" rel="stylesheet" type="text/css"><style type="text/css">
<!--
a:link {
color: #000000;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #EBE9ED;
}
a:hover {
text-decoration: none;
color: #CC3300;
}
a:active {
text-decoration: none;
}
.стиль1 {
font-size: 24px;
font-weight: bold;
font-style: italic;
color: #FF0000;
}
-->
</style></head>
<body>
<div class="container">
<div class="container1">
<?php include ("blocks/logotip.php"); ?>
<div class="header"></div>
</div>
<div class="container4">
<?php include ("blocks/meny.php"); ?>
<div class="myin_body">
<h2><p><b> Форма для загрузки файлов </b></p></h2>
<form action="add_file.php" method="post" enctype="multipart/form-data">
<input type="file" name="filename"><br>
<input type="submit" value="Загрузить"><br>
</form>
<?php
$file = 'Kalendar.csv';
if (($handle = fopen($file, 'r')) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ';')) !== FALSE) {
$arr[] = $data;
}
fclose($handle);
}
$serialize = serialize($arr);
$query = "INSERT INTO `mygadjet_donbas`.`zabeg_b` (`id`, `zabeg_b`) VALUES (NULL, '$serialize')";
$sql = mysql_query($query) or die(mysql_error());
?>
</div>
</div>
</div>
</body>
</html>
Georg-71$file = 'Kalendar.csv';
меняй на
$file = $_FILES['filename']['tmp_name'];
if(!empty($_FILES['filename']['tmp_name'])){
$file = $_FILES['filename']['tmp_name'];
if (($handle = fopen($file, 'r')) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ';')) !== FALSE) {
$arr[] = $data;
}
fclose($handle);
}
$serialize = serialize($arr);
$query = "INSERT INTO `mygadjet_donbas`.`zabeg_b` (`id`, `zabeg_b`) VALUES (NULL, '$serialize')";
$sql = mysql_query($query) or die(mysql_error());
}
И проверь заодно структуру своего csv-файла, чтобы разделение было символом
;
Georg-71
17.01.2011 - 19:25
А таблица у меня имеет всего три поля ((( id, поле BLOB для файла, и id_zabeg)))
Таблица расчитана что после загрузки в нее файла чтоб он открылся для просмотра и все.
Georg-71
Тогда чем тебе не подошел вариант с move_uploaded_file() ?
Georg-71
17.01.2011 - 19:41
SNUS Огромное спасибо загрузило успешно ша буду выводить пытаться
Georg-71
17.01.2011 - 19:48
А вот с открытием проблем нехочет открывать ругается
(((Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /***/add_a.php on line 86
вот эта строка $row = mysql_fetch_assoc($sq);
Georg-71
17.01.2011 - 19:56
Нашел ошибку. Зато вот как он мне все вывел
)
[4] => Array
(
[0] => 1
[1] => 3444
[2] => 23
[3] =>
)
[5] => Array
(
[0] => 1
[1] => 3444
[2] => 23
[3] =>
)
На месте [3] => должен был быть текст
Georg-71
17.01.2011 - 20:01
<?php include ("blocks/meny.php"); ?>
<div class="myin_body">
<?php
$query = "SELECT `id`, `result` FROM `zabeg_b` WHERE `id` = '3'";
$sql = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_assoc($sql);
$arr = unserialize($row['result']);
echo '<pre>';
print_r($arr);
echo '</pre>';?>
</div>
</div>
</div>
</body>
</html>
if(!empty($_FILES['filename']['tmp_name'])){
$file = $_FILES['filename']['tmp_name'];
if (($handle = fopen($file, 'r')) !== FALSE) {
$i = 0;
while (($data = fgetcsv($handle, 1000, ';')) !== FALSE) {
foreach($data as $key => $val){
$arr[$i][$key] = iconv('Windows-1251', 'UTF-8', $val);
}
$i++;
}
fclose($handle);
}
$serialize = serialize($arr);
$query = "INSERT INTO `mygadjet_donbas`.`zabeg_b` (`id`, `zabeg_b`) VALUES (NULL, '$serialize')";
$sql = mysql_query($query) or die(mysql_error());
}
Быстрый ответ:
Powered by dgreen
Здесь расположена полная версия этой страницы.