alleroy
@alleroy
Изучаю фреймворк laravel

Почему не загружается картинка в папку img?

Почему я не могу загрузить картинку в папку img???

bf244c392be443209415c24ca72538c0.png

Вот код:

<?php

include 'connect.php';
include 'crud-function.php';

if($_SERVER['REQUEST_METHOD'] === 'POST'){
    
    $input = $_POST['input'];
   
} else {
    
    $input = $_GET['status'];
    
}

switch ($input){

case 'add_products':
        
          if(!empty($_FILES)){
              if($_FILES['image']['error'] == 0){
                  
                  $tmp_file = $_FILES['image']['tmp_name'];
                  $filename = $_FILES['image']['name'];
                  
                  move_uploaded_file($tmp_file, "img/". $filename);
                  

                    $col_id_name = "id";
                    $row_id = $_POST['product_id'];
                    $table_name = "bibliotek_books";

                    $table_data;
                    $table_data['title'] = $_POST['title'];
                    $table_data['forfatter'] = $_POST['forfatter'];
                    $table_data['isbn_nr'] = $_POST['isbn_nr'];
                    $table_data['forlag'] = $_POST['forlag'];
                    $table_data['antal_sider'] = $_POST['antal_sider'];
                    $table_data['udgivelsesdato'] = $_POST['udgivelsesdato'];
                    $table_data['mini_text'] = $_POST['mini_text'];
                    $table_data['text'] = $_POST['text'];
                    $table_data['billede'] = $_FILES['image']['name'];
                    $categories = $_POST['category'];

                    $insert_id = create($table_name, $table_data);

                    foreach ($categories as $value){

                        create("bibliotek_books_cat", array("bibliotek_books_id"=>$insert_id, "bibliotek_category_id"=>$value));
                    }

                    header('Location: /Bibliotek/admin/index.php?page=products');
                  
                    
              }
              else{
                  echo 'Image cannot upload, plz try again';
              }
          }
          
        break;

        default:
       
        echo "Handler fejl";
}

?>


<?php

$bibliotek_category = "bibliotek_category";
$bibliotek_data = array("id","cat_navn");
$bibliotek_result = read($bibliotek_category, $bibliotek_data);

?>

<div id="header"><i id="fa" class="fa fa-bars fa-2x"></i></div>
<div id="main">
    <form action="include/handler.php" method="post" class="form-horizontal" enctype="multipart/form-data">
    
<fieldset>

<!-- Form Name -->
<legend><i id="fa" class="fa fa-bars"></i> Tilføje bog</legend>

<!-- Text input-->
<div class="control-group">
  <label class="control-label" for="title">Bog Navn</label>
  <div class="controls">
      <input id="title" name="title" type="text" value="<?php echo $title; ?>" placeholder="" class="input-xxlarge">
    
  </div>
</div>

<!-- Text input-->
<div class="control-group">
  <label class="control-label" for="forfatter">Forfatter</label>
  <div class="controls">
      <input id="forfatter" name="forfatter" type="text" value="<?php echo $forfatter; ?>" placeholder="" class="input-xxlarge">
    
  </div>
</div>

<!-- Text input-->
<div class="control-group">
  <label class="control-label" for="isbn_nr">ISBN.Nr</label>
  <div class="controls">
      <input id="isbn_nr" name="isbn_nr" type="text" value="<?php echo $isbn_nr; ?>" placeholder="" class="input-xxlarge">
    
  </div>
</div>

<!-- Select Basic -->
<div class="control-group">
  <label class="control-label" for="cat_navn">Kategorier</label>
  <div class="controls">
    
        
        <?php
        
        while ($bibliotek_row = mysqli_fetch_array($bibliotek_result)){
            
            $bibliotek_type = $bibliotek_row['cat_navn'];
            $bibliotek_id = $bibliotek_row['id'];
            
        
        ?>
        
        
        <input type="checkbox" name="category[]" value="<?php echo $bibliotek_id; ?>"> <?php echo $bibliotek_type; ?><br>
        
        
        <?php
        
        }
        
        ?>
      
    
  </div>
</div>

<!-- Text input-->
<div class="control-group">
  <label class="control-label" for="forlag">Forlag</label>
  <div class="controls">
      <input id="forlag" name="forlag" type="text" value="<?php echo $forlag; ?>" placeholder="" class="input-xxlarge">
    
  </div>
</div>

<!-- Text input-->
<div class="control-group">
  <label class="control-label" for="antal_sider">Sider</label>
  <div class="controls">
      <input id="antal_sider" name="antal_sider" type="text" value="<?php echo $antal_sider; ?>" placeholder="" class="input-xxlarge">
    
  </div>
</div>

<!-- Text input-->
<div class="control-group">
  <label class="control-label" for="udgivelsesdato">Udgivelsesdato</label>
  <div class="controls">
      <input id="udgivelsesdato" name="udgivelsesdato" type="text" value="<?php echo $udgivelsesdato; ?>" placeholder="" class="input-xxlarge">
    
  </div>
</div>

<!-- Textarea -->
<div class="control-group">
  <label class="control-label" for="textarea">Kort Beskrivelse</label>
  <div class="controls">                     
    <textarea id="textarea" name="mini_text"></textarea>
  </div>
</div>

<!-- Textarea -->
<div class="control-group">
  <label class="control-label" for="textarea">Om Bogen</label>
  <div class="controls">                     
    <textarea id="textarea" name="text"></textarea>
  </div>
</div>

<!-- File Button --> 
<div class="control-group">
  <label class="control-label" for="billede">BIllede</label>
  <div class="controls">
      <input id="billede" name="image" class="input-file" type="file" value="<?php echo $billede; ?>">
  </div>
</div>

<!-- Button -->
<div class="control-group">
  <label class="control-label" for="button"></label>
  <div class="controls">
      
        <input type="hidden" name="product_id" value="<?php echo $id; ?>">

        <input type="hidden" value="add_products" name='input'>
        
        <input id="button" type="submit" value="Save" name="button" class="btn btn-success">
        
        
  </div>
</div>

</fieldset>
</form>

</div>
  • Вопрос задан
  • 298 просмотров
Решения вопроса 1
sayber
@sayber Куратор тега PHP
Да, я программирую на PHP и еще асинхронно!
1) Покажите ошибку
2) Полный путь до директории img не пробывали указывать ?
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
berezuev
@berezuev
#define TRUE FALSE
chmod 0777 выставить не забыли?

А вообще, ошибку в таких случаях тоже надо указывать
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы