0

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

这是错误信息吗

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>

有人能帮助我吗。

4

2 回答 2

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)):
于 2013-10-15T14:42:02.473 回答
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

     }
于 2013-10-15T14:48:16.600 回答