Pessoal Alguém poderia me ajudar a alterar esse código para que ele possa enviar imagens para o banco de dados (MYQL). O código foi gerado pelo Dreamweaver através do Insert Record.
Código de envio:
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO noticiario (titulo, subtitulo, autor, noticia, manchete, imagem) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['titulo'], "text"),
GetSQLValueString($_POST['subtitulo'], "text"),
GetSQLValueString($_POST['autor'], "text"),
GetSQLValueString($_POST['noticia'], "text"),
GetSQLValueString($_POST['manchete'], "text"),
GetSQLValueString($_POST['imagem'], "text")); -----------------> Esse campo corresponde a o
envio da imagem, sei que
tenho que alterar para
$_files, mas não deu certo.
mysql_select_db($database_conn, $conn);
$Result1 = mysql_query($insertSQL, $conn) or die(mysql_error());
$insertGoTo = "../publicar-noticia.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: visualizacao.php", $insertGoTo));
}
?>
Esse é o formulário:
<div class="formularios">
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1" enctype="multipart/form-data" >
<table align="center" width="100%">
<tr valign="middle">
<td colspan="2">
<!--tabela informacoes principais-->
<div style="background:url(../../imagens/Untitled-1.jpg) repeat-x; width:900px">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="30%" scope="row"><span id="sprypassword1">
<label for="titulo2">Titulo da Notícia:<br />
</label>
<input name="titulo" type="text" id="titulo2" accesskey="t" tabindex="t" size="40" />
<span class="passwordRequiredMsg">A value is required.</span></span></th>
<td width="40%"><span id="sprypassword2">
<label for="subtitulo">Subtítulo:</label>
<br />
<input name="subtitulo" type="text" id="subtitulo" accesskey="s" tabindex="s" size="55" />
<span class="passwordRequiredMsg">A value is required.</span></span></td>
<td width="30%"><span id="sprytextfield1">
<label for="autor">Autor:<br />
</label>
<input name="autor" type="text" id="autor" accesskey="a" tabindex="a" size="40" />
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
</table>
</div>
<!--tabela informacoes principais-->
</td>
</tr>
<tr valign="baseline">
<td colspan="2" align="right" valign="top" nowrap="nowrap">
<div class="sessao" style="text-align:center">
<?php
// Include the CKEditor class.
include("ckeditor/ckeditor.php");
// Create a class instance.
$CKEditor = new CKEditor();
// Do not print the code directly to the browser, return it instead.
$CKEditor->returnOutput = true;
// Path to the CKEditor directory, ideally use an absolute path instead of a relative dir.
// $CKEditor->basePath = '/ckeditor/'
// If not set, CKEditor will try to detect the correct path.
$CKEditor->basePath = 'ckeditor/';
// Set global configuration (will be used by all instances of CKEditor).
$CKEditor->config['width'] = 900;
// Change default textarea attributes.
$CKEditor->textareaAttributes = array("cols" => 80, "rows" => 10);
// The initial value to be displayed in the editor.
$initialValue = '';
// Create the first instance.
$code = $CKEditor->editor("noticia", $initialValue);
echo $code;
?></div> </td>
</tr>
<tr valign="middle">
<td colspan="2">
<!--tabela manchete e publicar-->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="36%" rowspan="3" scope="row"><span id="sprytextarea1">
<label for="manchete">Manchete:<br />
</label>
<textarea name="manchete" id="manchete" cols="50" rows="8" accesskey="m" tabindex="m"></textarea>
<span class="textareaRequiredMsg">A value is required.</span></span></th>
<td width="64%" height="79"><span id="sprytextfield2">
<label for="imagem">Selecionar Imagem (Galeria de Conteúdo):<br />
</label>
<!-------------------- Campo de inserção da imagem ------------------------------------------->
<input name="imagem" type="file" id="imagem" accesskey="i" tabindex="i" />
<span class="textfieldRequiredMsg">A value is required.</span></span></td>
</tr>
<tr>
<td><input type="submit" value="Publicar:" style="height:2em; width:12.25em; font-size: 2em; color:#600"/></td>
</tr>
</table>
<!--final tabela manchete e publicar-->
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<p> </p>
</div>
Espero que possam me ajudar.
rogerleonino@hotmail.com