2011-11-29 74 views
1

大家好,我希望你能幫助我用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!"; 
} 
} 

?> 

問題是它沒有給我任何錯誤,也沒有上傳到數據庫或將圖像上傳到服務器上的文件夾。

我在做什麼錯?

謝謝你,希望你能幫助我

+4

沒有收到任何錯誤消息?添加你自己的!用調試語句跟蹤代碼以找出問題。 –

+1

似乎在這裏可以正常工作,請嘗試在'<?php'之後添加'error_reporting(E_ALL);'並查看是否會產生任何錯誤。 此外,我注意到你正在將它上傳到父文件夾(../)中的文件夾是否應該是? –

+0

您應該添加一對「斷點」,在條件之前嘗試var_dump($ _FILES),這可能是文件夾權限的問題。 –

回答

1

也許你沒有寫權限在target_path。你檢查了嗎?可能你沒有看到任何錯誤信息,因爲你禁用了display_errors(在php.ini中)。你可以激活的display_errors或在您的服務器激活日誌記錄:

http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors

http://www.php.net/manual/en/errorfunc.configuration.php#ini.log-errors

如果您沒有訪問配置文件,您可以在您的腳本試試這個:

ini_set('display_errors','On'); 
+0

另外,我已經設置了ini_set('display_errors','On'),現在不給我任何錯誤, 需要更多的數據來診斷問題? – user569176

0

嘗試對上傳文件夾應用正確的權限,在大多數ftp瀏覽器中,右鍵單擊文件夾>文件屬性或權限,並將其設置爲777. 通過SSH,是:chmod -Rf 777 foldername