So I have 2 files add.php for upload-a and an index for output. This code works fine on the local XAMPP server, and on some site it doesn’t display a photo, and so the text is fine. What’s the problem? Help add.php:

<?php require_once('dbConfig.php'); $upload_dir = 'uploads/'; if(isset($_POST['btnSave'])){ $name = $_POST['name']; $position = $_POST['position']; $imgName = $_FILES['myfile']['name']; $imgTmp = $_FILES['myfile']['tmp_name']; $imgSize = $_FILES['myfile']['size']; if(empty($name)){ $errorMsg = 'ayble nese yaz'; }elseif(empty($position)){ $errorMsg = 'nese yazda blee'; }elseif(empty($imgName)){ $errorMsg = 'wekil sec cuwka'; }else{ //get image extension $imgExt = strtolower(pathinfo($imgName, PATHINFO_EXTENSION)); //allow extenstion $allowExt = array('jpeg', 'jpg', 'png', 'gif'); //random new name for photo $userPic = time().'_'.rand(1000,9999).'.'.$imgExt; //check a valid image if(in_array($imgExt, $allowExt)){ //check image size less than 5MB if($imgSize < 5000000){ move_uploaded_file($imgTmp ,$upload_dir.$userPic); }else{ $errorMsg = 'Image too large'; } }else{ $errorMsg = 'Please select a valid image'; } } //check upload file not error than insert data to database if(!isset($errorMsg)){ $sql = "insert into images(name, position, photo) values('".$name."', '".$position."', '".$userPic."')"; $result = mysqli_query($conn, $sql); if($result){ $successMsg = 'Vse boomba kimi'; header('refresh:3;index.php'); }else{ $errorMsg = 'Error '.mysqli_error($conn); } } } ?> <!DOCTYPE html> <html> <head> <style> body { font-family: sans-serif; background-color: #eeeeee; } .file-upload { background-color: #ffffff; width: 600px; margin: 0 auto; padding: 20px; } .file-upload-btn { width: 100%; margin: 0; color: #fff; background: #1FB264; border: none; padding: 10px; border-radius: 4px; border-bottom: 4px solid #15824B; transition: all .2s ease; outline: none; text-transform: uppercase; font-weight: 700; } .file-upload-btn:hover { background: #1AA059; color: #ffffff; transition: all .2s ease; cursor: pointer; } .file-upload-btn:active { border: 0; transition: all .2s ease; } .file-upload-content { display: none; text-align: center; } .file-upload-input { position: absolute; margin: 0; padding: 0; width: 100%; height: 100%; outline: none; opacity: 0; cursor: pointer; } .image-upload-wrap { margin-top: 20px; border: 4px dashed #1FB264; position: relative; } .image-dropping, .image-upload-wrap:hover { background-color: #1FB264; border: 4px dashed #ffffff; } .image-title-wrap { padding: 0 15px 15px 15px; color: #222; } .drag-text { text-align: center; } .drag-text h3 { font-weight: 100; text-transform: uppercase; color: #15824B; padding: 60px 0; } .file-upload-image { max-height: 200px; max-width: 200px; margin: auto; padding: 20px; } .remove-image { width: 200px; margin: 0; color: #fff; background: #cd4535; border: none; padding: 10px; border-radius: 4px; border-bottom: 4px solid #b02818; transition: all .2s ease; outline: none; text-transform: uppercase; font-weight: 700; } .remove-image:hover { background: #c13b2a; color: #ffffff; transition: all .2s ease; cursor: pointer; } .remove-image:active { border: 0; transition: all .2s ease; }</style> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Uploadimage</title> <link rel="stylesheet" type="text/css" href="./bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="./bootstrap/css/bootstrap-theme.min.css"> </head> <body> <div class="navbar navbar-default"> <div class="container"> <div class="navbar-header"> <h3 class="navbar-brand">Sekil soxusdur getsin</h3> </div> </div> </div> <div class="container"> <div class="page-header"> <h3>Tep teze <a class="btn btn-default" href="index.php"> <span class="glyphicon glyphicon-arrow-left"></span> &nbsp;Geri </a> </h3> </div> <?php if(isset($errorMsg)){ ?> <div class="alert alert-danger"> <span class="glyphicon glyphicon-info"> <strong><?php echo $errorMsg; ?></strong> </span> </div> <?php } ?> <?php if(isset($successMsg)){ ?> <div class="alert alert-success"> <span class="glyphicon glyphicon-info"> <strong><?php echo $successMsg; ?> - 2 saniye doz zor olacaq</strong> </span> </div> <?php } ?> <form action="" method="post" enctype="multipart/form-data" class="form-horizontal"> <div class="form-group"> <label for="name" class="col-md-2">NEse yaz getsin</label> <div class="col-md-10"> <input type="text" name="name" class="form-control"> </div> </div> <div class="form-group"> <label for="position" class="col-md-2">Haqqinda yaz</label> <div class="col-md-10"> <input type="text" name="position" class="form-control"> </div> </div> <div class="form-group"> <label for="photo" class="col-md-2">Sekilin ozu bled</label> <div class="col-md-10"> <input type="file" name="myfile"> </div> </div> <div class="form-group"> <label class="col-md-2"></label> <div class="col-md-10"> <button type="submit" class="btn btn-success" name="btnSave"> <span class="glyphicon glyphicon-save"></span>go ver </button> </div> </div> </form> </div> <div class="text"></div> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> </body> </html> 

index.php:

 <?php require_once('dbConfig.php'); $upload_dir = 'uploads/'; if(isset($_GET['delete'])){ $id = $_GET['delete']; //select old photo name from database $sql = "select photo from images where id = ".$id; $result = mysqli_query($conn, $sql); if(mysqli_num_rows($result) > 0){ $row = mysqli_fetch_assoc($result); $photo = $row['photo']; unlink($upload_dir.$photo); //delete record from database $sql = "delete from images where id=".$id; if(mysqli_query($conn, $sql)){ header('location:sekil.php'); } } } ?> <!DOCTYPE html> <html> <head> <style> .gallery picture { display: inline-block; margin: 5px; position: relative; overflow: hidden; width: 200px; height: 200px; } .gallery img { position: absolute; top: 50%; transform: translateY(-50%); width: 100%; } html { height: 100%; } body { background-color: #2590EB; height: 100%; } .wrapper { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; } .wrapper .file-upload { height: 100px; width: 100px; border-radius: 100px; position: absolute; top: 0px; right: 0px; display: flex; justify-content: center; align-items: center; border: 4px solid #FFFFFF; overflow: hidden; background-image: linear-gradient(to bottom, #2590EB 50%, #FFFFFF 50%); background-size: 100% 200%; transition: all 1s; color: #FFFFFF; font-size: 100px; } .wrapper .file-upload a { height: 200px; width: 200px; position: absolute; top: 0; left: 0; opacity: 0; cursor: pointer; } .wrapper .file-upload:hover { background-position: 0 -100%; color: #2590EB; } @media screen and (max-width:768px){ .wrapper .file-upload { height: 50px; width: 50px; border-radius: 100px; position: absolute; top: 0px; right: 0px; display: flex; justify-content: center; align-items: center; border: 4px solid #FFFFFF; overflow: hidden; background-image: linear-gradient(to bottom, #2590EB 50%, #FFFFFF 50%); background-size: 100% 200%; transition: all 1s; color: #FFFFFF; font-size: 50px; } } </style> <title>Uploadimage</title> <link href="./css/font-awesome.min.css" rel="stylesheet"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" type="text/css" href="./bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" type="text/css" href="./bootstrap/css/bootstrap-theme.min.css"> </head> <body> <div class="navbar navbar-default"> <div class="container"> <div class="navbar-header"> <h3 class="navbar-brand">PHP upload image</h3> </div> </div> </div> <div class="container"> <div class="wrapper"> <div class="file-upload"> <form action="" method="post" enctype="multipart/form-data" > <a href="add.php"> </a> <i class="fa fa-arrow-up"></i> </form> </div> </div> <?php $sql = "select * from images"; $result = mysqli_query($conn, $sql); if(mysqli_num_rows($result)){ while($row = mysqli_fetch_assoc($result)){ ?> <div class="gallery"> <picture> <img src="<?php echo $upload_dir.$row['photo'] ?>" > </picture> </div> <a class="btn btn-info" href="edit.php?id=<?php echo $row['id'] ?>"> <span class="glyphicon glyphicon-edit"></span>Deyiw sekli </a><br> <a class="btn btn-danger" href="sekil.php?delete=<?php echo $row['id'] ?>" onclick="return confirm('100% sikdir elirsen?')"> <span class="glyphicon glyphicon-remove-circle"></span>Sikdir ele </a> <a class="btn btn-danger" href="sekil.php?download=<?php echo $row['id'] ?>" > <span class="glyphicon glyphicon-remove-circle"></span>Yukle bled </a> <?php } } ?> </div> </body> </html> 

    1 answer 1

    Try to specify paths using the magic constant __DIR__ , which contains the path to the current folder.

    It is also possible php on the server does not have a mysqli