【问题标题】:Upload multiple files with php and mysql?用php和mysql上传多个文件?
【发布时间】:2012-01-09 03:23:50
【问题描述】:

大家好,希望大家能帮到我

问题是这样的,我有一个带有以下代码的表单:

<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!";
}
}

?>

问题是它没有给我错误,也没有上升到数据库或将图像上传到服务器上的文件夹。

我做错了什么?

谢谢你,希望你能帮助我

【问题讨论】:

  • 没有收到任何错误消息?添加你自己的!使用调试语句跟踪代码以隔离问题。
  • 这里似乎可以正常工作,尝试在&lt;?php 之后添加error_reporting(E_ALL); 并查看它是否会产生任何错误。另外,我注意到您正在将其上传到父文件夹 (../) 中的文件夹,应该是这样吗?
  • 你应该添加几个“断点”,在条件之前尝试 var_dump( $_FILES ),可能是文件夹权限的问题。
  • ´警告:无法修改标头信息 - 标头已由 /home/sitios/public_html 中的(输出开始于 /home/sitios/public_html/farmland/farmland/ad5/uploadernoticias.php:3)发送/farmland/farmland/ad5/uploadernoticias.php 第 36 行'
  • 该文件在 Ad5 uploader.php / 中并转到 images 文件夹 / 属性文件夹在 Ad5 之外 我的电脑工作正常!但由于我的域无法正常工作,请尝试将 .. /imagenes/noticias news 不带 /.我也有 error_reporting (E_ALL) 并且我得到错误

标签: php mysql file upload


【解决方案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'); 

【讨论】:

  • 另外,我已经设置了ini_set('display_errors', 'On'),现在没有出现任何错误,需要更多数据来诊断问题吗?
【解决方案2】:

尝试对上传文件夹应用正确的权限,在大多数 ftp 浏览器中,右键单击文件夹 > 文件属性或权限,并将其设置为 777。 通过 SSH 这将是:chmod -Rf 777 foldername

【讨论】:

    猜你喜欢
    • 2011-12-27
    • 1970-01-01
    • 1970-01-01
    • 2012-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多