我在上传文件时遇到问题。这是我的表格:
<form enctype="multipart/form-data" action="transact.php" method="POST">
<table>
<tr>
<td>Nadpis:</td>
<td><input type="text" id="title" name="title" value="<?php echo htmlspecialchars($title); ?>" /></td></tr>
<tr>
<td>Text článku:</td>
<td><textarea id="text" name="text" cols="55" rows="20"><?php if(!empty($a_text)) { echo htmlspecialchars($a_text); } ?></textarea></td>
</tr><tr>
<td>Obrázok k článku:</td>
<td><input type="file" name="uploadfile" /></td></tr>
<tr><td> </td>
<td>
<?php
if ($_SESSION['access_level'] < 2) {
echo '<input type="hidden" name="user_id" value="'. $user_id. '"/>';
}
if(empty($article_id)) {
echo '<input type="submit" name="action" value="Odoslat" />';
} else {
echo '<input type="hidden" name="article_id" value="' .$article_id. '"/>';
echo '<input type="submit" name="action" value="Ulozit" />';
}
?>
</td>
</tr>
</table>
</form>
当我运行脚本 transact.php 时出现错误:注意:未定义的索引:第 138 行的 E:\xampp\htdocs\capitals\transact.php 中的 上传文件,当我输入 print_r($_FILES) 时,我得到的只是Array() 值php.ini 文件中的最大上传大小设置为 128 MB
我的交易脚本:
case 'Odoslat':
session_start();
$text = (isset($_POST['text']))? $_POST['text']: '';
$nadpis = (isset($_POST['title']))? $_POST['title']: '';
$image = (isset($_FILES['uploadfile']))? imagecreatefromjpeg($_FILES['uploadfile']['tmp_name']): '';
print_r($_FILES); // it writes Array()
if(isset($_SESSION['id']) && !empty($nadpis) && !empty($text) && $_FILES['uploadfile']['error'] == UPLOAD_ERR_OK) //here it indicates error
{
$ext = '.jpg';
$query = 'INSERT INTO articles (article_id, user_id, a_text, title, submit_date)
VALUES(NULL, '. $_SESSION['id']. ', "'. mysql_real_escape_string($text, $db). '", "'.
mysql_real_escape_string($nadpis, $db). '", "' . date('Y-m-d H:i:s'). '")';
mysql_query($query, $db) or die(mysql_error($db));
$clanok_id = mysql_insert_id($db);
$query = 'INSERT INTO foto (foto_id, article_id)
VALUES (NULL, '. $clanok_id. ')';
mysql_query($query, $db) or die(mysql_error($db));
if(!empty($image))
{
$last_id = mysql_insert_id($db);
$image_name = $last_id. $ext;
imagejpeg($image, $dir. '/'. $image_name, 100);
}
else
{
$last_id = mysql_insert_id($db);
$image_name = 'caps.jpg';
}
$priecinok = 'images/';
$place = $priecinok. $image_name;
$query = 'UPDATE foto
SET foto_path = "'. $place. '" WHERE foto_id = '. $last_id;
mysql_query($query, $db) or die(mysql_error($db));
$query = 'UPDATE articles
SET foto_id = '. $last_id. ' WHERE article_id = '. $clanok_id;
mysql_query($query, $db) or die(mysql_error($db));
$redirect = 'index.php';
}
else
{
$chyba = 'Nepodarilo sa nahrat clanok!';
$redirect = 'index.php?chyba='. $chyba;
}
break;
请问我该如何修复?如果有人帮助我,我将不胜感激...