dsft8327 2011-11-29 19:38
浏览 100

用php和mysql上传多个文件?

Hello everyone and I hope you can help me

The problem is this, I have a form with the following code:

<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>

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

?>

The problem is that it gives me no error, nor rises to the database or upload images to the folders on the server.

What am I doing wrong?

Thank you and hope you can help me

  • 写回答

2条回答 默认 最新

  • doujiao7520 2011-11-29 19:51
    关注

    Maybe you don't have write permission in target_path. Did you check it? Probably you don't see any error message because you have display_errors disabled (in php.ini). You could activate display_errors or activate logging in your server:

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

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

    If you don't have access to configuration files, you can try this in your script:

    ini_set('display_errors','On'); 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错