大家好,我希望你能幫助我用php和mysql上傳多個文件?
問題是這樣的,我有下面的代碼形式:
<form action="uploadernoticias.php" method="post" enctype="multipart/form-data" name="form1" class="nice" id="form1">
<h2>Insertar Noticias</h2>
<p class="left">
<label>Titulo</label>
<input name="caption" type="text" class="inputText" id="caption" />
<label>Imagen/Foto</label>
<input type="file" name="uploadedfile" id="uploadedfile" class="inputText" />
</p>
<p class="right">
<label>Description:</label>
<textarea name="contenido" cols="" rows="10" class="inputText_wide" id="contenido"></textarea>
<br clear="all" />
<button class="green" type="submit">Listo! - Subir Noticias</button>
</p>
<div class="clear"></div>
</form>
和文件uploadernoticias.php:
<?php
/*##################--[Obteniendo datos del formulario - Propiedades]*/
// Nombre
$caption = $_POST['caption'];
// Contenido
$contenido= $_POST['contenido'];
/*##################--[Definiendo la carpeta imagenes para las Propiedades]*/
$target_path = "../imagenes/noticias/";
/*##################--[Seteando las imagenes]*/
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);
$file_path = basename($_FILES['uploadedfile']['name']);
$file_size = basename($_FILES['uploadedfile']['size']);
if ($file_size > '20452525'){
header('Location: gallery.php?id=error');
}
else
{
/*##################--[Informando si se subio correctamente entonces..]*/
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
//echo "The file ". basename($_FILES['uploadedfile']['name']).
//" has been uploaded<br><br>Link: <a href=\"http://www.thetastingroomokc.com/gallery/". basename($_FILES['uploadedfile']['name']) ."\">http://www.thetastingroomokc.com/gallery/". basename($_FILES['uploadedfile']['name']) ."</a>";
/*##################--[Insertar en la base de datos]*/
mysql_query("INSERT INTO noticias VALUES ('', '$caption', '$contenido', '$file_path')");
//echo $file_size.' is how big your file is. It was transferred.';
/*##################--[Luego, enviar a una pagina]*/
header('Location: noticias.php');
} else{
echo "There was an error uploading the file, please try again!";
}
}
?>
問題是它沒有給我任何錯誤,也沒有上傳到數據庫或將圖像上傳到服務器上的文件夾。
我在做什麼錯?
謝謝你,希望你能幫助我
沒有收到任何錯誤消息?添加你自己的!用調試語句跟蹤代碼以找出問題。 –
似乎在這裏可以正常工作,請嘗試在'<?php'之後添加'error_reporting(E_ALL);'並查看是否會產生任何錯誤。 此外,我注意到你正在將它上傳到父文件夾(../)中的文件夾是否應該是? –
您應該添加一對「斷點」,在條件之前嘗試var_dump($ _FILES),這可能是文件夾權限的問題。 –