上传图片时出错 - move_uploaded_file

时间:2013-10-15 14:39:41

标签: php

我住在巴西,发现这个网站有问题。发现它非常好。

此错误消息

Warning: move_uploaded_file(): The second argument to copy() function cannot be a directory in C:\wamp\www\imoveis\cadastro.php on line 22
Call Stack


Warning: move_uploaded_file(): Unable to move 'C:\wamp\tmp\php6DC1.tmp' to 'banners/' in C:\wamp\www\imoveis\cadastro.php on line 22

这是要给出麻烦的代码行;

if(move_uploaded_file($banner_tmp, "banners/".$banner)):

此页面为cadastro.php

<?php 
    include_once "conexao/config.php";
    include_once "functions/functions.php";


    if(isset($_POST['cadastrar'])):
        $titulo = filter_input(INPUT_POST, 'titulo', FILTER_SANITIZE_STRING);
        $descricao = filter_input(INPUT_POST, 'descricao', FILTER_SANITIZE_STRING);
        $banner_tmp = $_FILES['banner']['tmp_name'];

        $larguraPermitida = 900;
        $alturaPermitida = 300;
        $dadosFoto = getimagesize($banner_tmp);
        list($largura, $altura ,$numero, $tipo)= $dadosFoto;

            if($largura > $larguraPermitida):
                        echo "Largura não pode ser maior que ".$larguraPermitida;
                            elseif($altura > $alturaPermitida):
                                echo "Altura não pode ser maior que ".$alturaPermitida;
                            else:
                if(move_uploaded_file($banner_tmp, "banners/".$banner)):
                        cadastrarBanners($titulo,$banner,$descricao);
                        else:
                            echo "erro ao fazer upload";
                endif;
            endif;
        endif;



?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<link rel="stylesheet" href="estilo/estilo.css" type="text/css" />

<link rel="stylesheet" href="estilo/acadastrar_admin.css" type="text/css">
<link rel="stylesheet" href="estilo/estilo.css" type="text/css" />
<link rel="stylesheet" href="estilo/button_iniciar.css" type="text/css">
<link rel="stylesheet" href="estilo/button_sobre.css" type="text/css">
<link rel="stylesheet" href="estilo/button_investir.css" type="text/css">
<link rel="stylesheet" href="estilo/button_imoveis.css" type="text/css">
<link rel="stylesheet" href="estilo/coin-slider-styles.css" type="text/css">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cadastrar Banners</title>
</head>

<body>
<table width="1348" align="center" cellspacing="0" cellpadding="0">
  <tr>
    <th scope="col">
            <div id="topo">
            <div id="telefone">
                055 81 9992-5152
            </div>
        </div>
    </th>
  </tr>
  <tr>
    <td><?php include_once('menu.php');?></td>
  </tr>
  <tr>
    <td> <div id="conteudo">
        <?php include_once('menu.php');?>
        <div id="cadastrar_administrador">

        <form action="" method="post" enctype="multipart/form-data">
        <fieldset class="first">
            <label  class="labelOne" for="titulo">Titulo:</label>            
            <input type="text" name="titulo"/>

            <label for="descricao">Descrição:</label>
            <input type="text" name="descricao"/>

            <label for="banner">Banner:</label>
            <input type="file" name="banner"/>

            <label class="btn" for="submit"></label>
            <input class="btn" type="submit" name="cadastrar" value="Cadastrar Banner"/>
        </fieldset>
        </form>

    </div>

    </div>

    </td>
  </tr>
  <tr>
    <td><div align="center" id="rodape">
sjncsjknckjsdc
    </div>
</td>
  </tr>
</table>
</body>
</html>

请有人帮助我。

2 个答案:

答案 0 :(得分:1)

这是导致问题的一行:

if(move_uploaded_file($banner_tmp, "banners/".$banner)):

你应该传递一个像这样的绝对路径:

if(move_uploaded_file($banner_tmp, dirname(__FILE__) . "/banners/".$banner)):

if(move_uploaded_file($banner_tmp, "C:/some/folder/banners/".$banner)):

答案 1 :(得分:0)

横幅/错误

你应该这样写 if(move_uploaded_file($ banner_tmp,“/ banners / $ banner”)):

简单的例子..仅供演示......

 <?php
     $uploads_dir = '/uploads';

     foreach ($_FILES["pictures"]["error"] as $key => $error) 
     {
           if ($error == UPLOAD_ERR_OK) 
           {
               $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
               $name = $_FILES["pictures"]["name"][$key];
               move_uploaded_file($tmp_name, "$uploads_dir/$name");
           } 
      }
  ?>


   /*Try this working code for move_uploaded_files */

   <?php

          if(isset($_FILES['uploaded'])){
          $target = "galleries/".basename($_FILES['uploaded']['name']) ;
          print_r($_FILES);

           if(move_uploaded_file($_FILES['uploaded']['tmp_name'],$target)) 
                  echo  "OK!";//$chmod o+rw galleries

     }