2016-08-09 5 views
1

Когда я загружаю файл на свой localhost, он отлично работает. Но когда я загружаю его на сервер, он не работает. Изображение отображается на этой странице правильно из того же каталога, но у него есть проблема при загрузке файла в этот каталог.PHP: файл изображений не загружается на сервер?

<!DOCTYPE html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <title>Belvic Print - Home page</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=3.0, user-scalable=yes"/> 
    <meta name="description" content="Printing template"> 
    <meta name="author" content="Netbase"> 
    <!--Add css lib--> 
    <link href='http://fonts.googleapis.com/css?family=Roboto:500,300,700,400' rel='stylesheet' type='text/css'> 
    <link href='https://fonts.googleapis.com/css?family=Arimo:500,300,700,400' rel='stylesheet' type='text/css'> 
    <link href='http://fonts.googleapis.com/css?family=Roboto+Condensed:500,300,700,400' rel='stylesheet' type='text/css'> 
    <link rel="stylesheet" href="bootstrap-3.3.6-dist/css/bootstrap.min.css"> 
    <link rel="stylesheet" href="bootstrap-3.3.6-dist/font-awesome-4.5.0/css/font-awesome.css"> 
    <link rel="stylesheet" href="sidebar.css"> 
    <script src="bootstrap-3.3.6-dist/js/jquery-1.12.2.min.js"></script> 
    <script src="bootstrap-3.3.6-dist/js/bootstrap.min.js"></script> 
    <script src="code_adimn.js"></script> 
    <script src="script.js"></script> 


    <style> 
     body{ 
      position: relative; 
      overflow-x: hidden; 
     } 
     .main-container{ 
      margin:0; 
      padding:0; 
     } 

     .submit_button{ 
      border: none; 
      margin-top: 5%; 
      padding: 10px; 
     } 
     label.myLabel input[type="file"] { 
      position: fixed; 
      top: -1000px; 
     } 
     .col-lg-offset-4{ 
      margin-bottom: 5%; 
     } 

     .row{ 
      margin-top: 3%; 
     } 
     /***** Example custom styling *****/ 
     .myLabel { 
      /*border: 2px solid #AAA;*/ 
      padding: 10px; 

      margin-top: 5%; 
      background: #DDD; 
      display: inline-block; 
     } 

     .myLabel:hover { 
      background: #CCC; 
     } 

     .myLabel:active { 
      background: #CCF; 
     } 

     .myLabel :invalid + span { 
      color: #A44; 
     } 

     .myLabel :valid + span { 
      color: #4A4; 
     } 


    </style> 
</head> 

<body> 

<div class="container-fluid main-container"> 

    <div class="navibar"> 
     <div class="fa fa-bars"> <span> Menu Bar </span></div> 
     <ul> 
      <div class="fa fa-close"></div> 
      <h2 class="admin">Admin Panel</h2> 
      <li><a href="#first">Image 1</a></li> 
      <li><a href="#second">Image 2</a></li> 
      <li><a href="#third">Image 3</a></li> 

     </ul> 
    </div> 

    <div class="row img-row"> 
     <div id="first" class="rows col-lg-6 col-sm-10 col-sm-offset-1 col-xs-10 col-xs-offset-1 col-lg-offset-4"> 
      <?php 
      include("db.php"); 
      $res = mysqli_query($conn, "SELECT * FROM image WHERE id=1"); 
      while ($record = mysqli_fetch_array($res)) { 

      ?> 

      <img src="<?php echo "../images/slider/home/" . $record['image1']; ?>" alt="" width="100%">//This image is displaying correctly from same directory 
      <form enctype="multipart/form-data" action="slider.php" method="POST" > 
       <label class="myLabel"> 
        <input type="file" name="myfile1"/> 
        <span>Change Picture</span> 
       </label> 
       <input name="submit1" type="submit" class="submit_button"> 
       <div class="clearfix"></div> 
      </form> 

      <form action="slider.php" method="POST" enctype="multipart/form-data"> 
       <label name="description">Enter the heading: </label> 
       <input type="text" name="heading1" class="form-control" placeholder="Enter the heading" value="<?php echo $record['image2']; ?>"> 
       <br> 
       <label name="description">Enter the Description</label> 
       <textarea name="description1" class="form-control" rows="3"><?php echo $record['image3'];} ?></textarea> 
       <input name="submit_content1" type="submit" class="pull-left submit_button"> 

      </form> 
     </div> 


     <div id="second" class="rows col-lg-6 col-sm-10 col-sm-offset-1 col-xs-10 col-xs-offset-1 col-lg-offset-4"> 
      <?php 
      $res1 = mysqli_query($conn, "SELECT * FROM image WHERE id=1"); 
      while ($record1 = mysqli_fetch_array($res1)) { 
      ?> 
      <img src="<?php echo "../images/slider/home/" . $record1['image4']; ?>" alt="kk" width="100%"> 
      <form action="slider.php" method="POST" enctype="multipart/form-data"> 
       <label class="myLabel"> 
        <input type="file" name="myfile2"/> 
        <span>Upload Picture</span> 
       </label> 
       <input name="submit2" type="submit" class="submit_button"> 
       <div class="clearfix"></div> 
      </form> 
      <form action="slider.php" method="POST" enctype="multipart/form-data"> 
       <label name="description">Enter the heading: </label> 
       <input type="text" name="heading2" class="form-control" placeholder="Enter the heading" value="<?php echo $record1['image5']; ?>"> 
       <br> 
       <label name="description">Enter the Description</label> 
       <textarea name="description2" class="form-control" rows="3"><?php echo $record1['image6'];} ?></textarea> 
       <input name="submit_content2" type="submit" class="pull-left submit_button"> 

      </form> 
     </div> 

     <div id="third" class="rows col-lg-6 col-sm-10 col-sm-offset-1 col-xs-10 col-xs-offset-1 col-lg-offset-4"> 

      <?php 
      $res2 = mysqli_query($conn, "SELECT * FROM image WHERE id=1"); 
      while ($record2 = mysqli_fetch_array($res2)) { 
      ?> 
      <img src="<?php echo "../images/slider/home/" . $record2['image7']; ?>" alt="" width="100%"> 
      <form action="slider.php" method="POST" enctype="multipart/form-data"> 
       <label class="myLabel"> 
        <input type="file" name="myfile3"/> 
        <span>Upload Picture</span> 
       </label> 
       <input name="submit3" type="submit" class="submit_button"> 
       <div class="clearfix"></div> 
      </form> 
      <form action="slider.php" method="POST" enctype="multipart/form-data"> 
       <label name="description">Enter the heading: </label> 
       <input type="text" name="heading3" class="form-control" placeholder="Enter the heading" value="<?php echo $record2['image8']; ?>"> 
       <br> 
       <label name="description">Enter the Description</label> 
       <textarea name="description3" class="form-control" rows="3"><?php echo $record2['image9'];} ?></textarea> 
       <input name="submit_content3" type="submit" class="pull-left submit_button"> 

      </form> 
     </div> 


    </div> 

</div> 

<?php 
if (isset($_POST['submit1'])) { 


    $type = $_FILES["myfile1"]["type"]; 
    $size = $_FILES["myfile1"]["size"]; 
    $temp = $_FILES["myfile1"]["tmp_name"]; 
    $error = $_FILES["myfile1"]["error"]; 
    if ($_FILES["myfile1"]["error"] < 1) { 
     if (exif_imagetype($_FILES["myfile1"]["tmp_name"]) != IMAGETYPE_PNG && exif_imagetype($_FILES["myfile1"]["tmp_name"]) != IMAGETYPE_JPEG 
      && exif_imagetype($_FILES["myfile1"]["tmp_name"]) != IMAGETYPE_GIF && exif_imagetype($_FILES["myfile1"]["tmp_name"]) != IMAGETYPE_ICO) { 
      echo 'There is problem with image file or file is not image'; 

     } else { 
      $name = "image_" . date('Y-m-d-H-i-s') . '_' . uniqid() . '.jpg'; 
      $upload = move_uploaded_file($temp, "../images/slider/home/" . $name); 

      if ($_FILES["myfile1"]["error"] > 0) { 
       echo "Some error in file upload"; 
      } else { 

       $sql = "UPDATE image SET image1='$name' WHERE id=1"; 
       if (mysqli_query($conn, $sql) && $upload) { 
        echo "Refresh the page to see the effect"; 
       } else { 
        echo "Some error while updating image"; 
       } 

      } 
     } 
    } 
    else { 
     echo "There is error in image file"; 
    } 

} 









//For image 2 

if (isset($_POST['submit2'])) { 


    $type = $_FILES["myfile2"]["type"]; 
    $size = $_FILES["myfile2"]["size"]; 
    $temp = $_FILES["myfile2"]["tmp_name"]; 
    $error = $_FILES["myfile2"]["error"]; 
    if ($_FILES["myfile2"]["error"] < 1) { 
     if (exif_imagetype($_FILES["myfile2"]["tmp_name"]) != IMAGETYPE_PNG && exif_imagetype($_FILES["myfile2"]["tmp_name"]) != IMAGETYPE_JPEG 
      && exif_imagetype($_FILES["myfile2"]["tmp_name"]) != IMAGETYPE_GIF && exif_imagetype($_FILES["myfile2"]["tmp_name"]) != IMAGETYPE_ICO) { 
      echo 'There is problem with image file or file is not image'; 

     } else { 
      $name = "image_" . date('Y-m-d-H-i-s') . '_' . uniqid() . '.jpg'; 
      $upload = move_uploaded_file($temp, "../images/slider/home/" . $name); 

      if ($_FILES["myfile2"]["error"] > 0) { 
       echo "Some error in file upload"; 
      } else { 

       $sql = "UPDATE image SET image4='$name' WHERE id=1"; 
       if (mysqli_query($conn, $sql) && $upload) { 
        echo "Refresh the page to see the effect"; 
       } else { 
        echo "Some error while updating image"; 
       } 

      } 
     } 
    } 
    else { 
     echo "There is error in image file"; 
    } 

} 

//For image 3 


if (isset($_POST['submit3'])) { 


    $type = $_FILES["myfile3"]["type"]; 
    $size = $_FILES["myfile3"]["size"]; 
    $temp = $_FILES["myfile3"]["tmp_name"]; 
    $error = $_FILES["myfile3"]["error"]; 
    if ($_FILES["myfile3"]["error"] < 1) { 
     if (exif_imagetype($_FILES["myfile3"]["tmp_name"]) != IMAGETYPE_PNG && exif_imagetype($_FILES["myfile3"]["tmp_name"]) != IMAGETYPE_JPEG 
      && exif_imagetype($_FILES["myfile3"]["tmp_name"]) != IMAGETYPE_GIF && exif_imagetype($_FILES["myfile3"]["tmp_name"]) != IMAGETYPE_ICO) { 
      echo 'There is problem with image file or file is not image'; 

     } else { 
      $name = "image_" . date('Y-m-d-H-i-s') . '_' . uniqid() . '.jpg'; 
      $upload = move_uploaded_file($temp, "../images/slider/home/" . $name); 

      if ($_FILES["myfile3"]["error"] > 0) { 
       echo "Some error in file upload"; 
      } else { 

       $sql = "UPDATE image SET image7='$name' WHERE id=1"; 
       if (mysqli_query($conn, $sql) && $upload) { 
        echo "Refresh the page to see the effect"; 
       } else { 
        echo "Some error while updating image"; 
       } 

      } 
     } 
    } 
    else { 
     echo "There is error in image file"; 
    } 

} 



//For content 1 
if (isset($_POST['submit_content1'])) { 

    $heading1 = $_POST['heading1']; 
    $description1 = $_POST['description1']; 

    $update1 = "UPDATE image SET image2='$heading1', image3='$description1' WHERE id=1"; 
    if (mysqli_query($conn, $update1)) { 
     echo ""; 
    } else { 
     echo mysqli_error($conn); 
    } 
} 


//For content 2 
if (isset($_POST['submit_content2'])) { 

    $heading2 = $_POST['heading2']; 
    $description2 = $_POST['description2']; 

    $update2 = "UPDATE image SET image5='$heading2', image6='$description2' WHERE id=1"; 
    if (mysqli_query($conn, $update2)) { 
     echo ""; 
    } else { 
     echo mysqli_error($conn); 
    } 
} 



//For content 3 
if (isset($_POST['submit_content3'])) { 

    $heading3 = $_POST['heading3']; 
    $description3 = $_POST['description3']; 

    $update3 = "UPDATE image SET image8='$heading3', image6='$description3' WHERE id=1"; 
    if (mysqli_query($conn, $update3)) { 
     echo ""; 
    } else { 
     echo mysqli_error($conn); 
    } 
} 

?> 


</body> 
+0

Какие ошибки вы получаете? –

+0

проверить права доступа к папке, обычная проблема, когда код работает в одном месте, но не другой –

+0

@Sami. Нет ошибки –

ответ

1

добавить эти 2 линии на php.ini (или его конец цитаты)

extension=php_mbstring.dll 
extension=php_exif.dll 

и, как я сказал использовать is_uploaded_file перед тем перемещение файлов :)

+0

- это php.ini, присутствующий на онлайн-сервере? –

+0

да, но это зависит от того, какой он сервер. Это частный или общий сервер, у вас есть ac панель или другие материалы для создания папки веб-домена? – MaximeK

+0

да .. у меня есть cpanel –

Смежные вопросы