۱ Aydin asad zadeh
مشکل اجرا نشدن کد
جامعه پی اچ پی ایجاد شده در ۲۳ اسفند ۱۴۰۱

سلام ممنون میشم بگید اشکال از کجاست طبق آموزش‌های این جلسه پیش رفتم ولی تو لوکال هاست به مشکل بر می‌خورم

session_start();
?>
html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <meta name="viewport"
  content="with=device-whith, initial-scale=1.0">
<style>
        .container{
            max-width: 600px;
            background: #fff;
            position: relative;
            height: 151px;
            border-radius: 5px;
            margin: 0 auto;
            margin-top: 300px;
            box-shadow: 0px 0px 6px 1px #efefef;
            padding-top: 118px;
        }
        .msg{
            position: absolute;
            top: -14px;
            background: #f9f9f9;
            width: 100%;
            padding: 14px 16px;
            box-sizing: border-box;
            color: #000;
            text-align: right;
            width: 85%;
            left: 0;
            transform: translate(8%,50%);
            border-right: 3px solid #00ceff;
        }
        form{
            justify-content: center;
            align-items: center;
            flex-direction: column;
            margin: 0 40px;
        }
        div.upload-wrapper{
            color: white;
            font-weight: bold;
            display: flex;
        }
        input[type="file"] {
            position: absolute;
            left: -9999px;
        }
        input[type="submit"]{
            color: white;
            background: #33bb30;
            margin: 10px 0;
            border-radius: 5px;
            font-weight: bold;
            padding: 9px 30px;
            cursor: pointer;
            border: none;
        }
        input[type="submit"]:hover{
            background: #555;
        }
        label[for="file-upload"]{
            padding: 0.7rem;
            display: inline-block;
            background: #5d9eff;
            cursor: pointer;
            border-radius: 0 5px 5px 0;
            border-left: 0;
        }
        label[for="file-upload"]:hover{
            background: #ca3103;
        }
        span.file-name{
            padding:0.7rem 14rem 0.7rem 0.7rem;
            white-space: nowrap;
            overflow: hidden;
            background: #ececec;
            color: black;
            border: 1px solid #ececec;
            border-radius: 5px 0 0 5px;
            border-right: 0;
            width: 100%;
        }
    style>
head>
<body>
    <div class="container">
        
          if(isset($_SESSION["msg"]) && $_SESSION["msg"]):?>
            <p class="msg"> echo $_SESSION ?>p>
             unset($_SESSION['msg']); ?>
         endif?>    
        <form method="POST" action="upload-file.php">
            <div class="upload-wrapper">
                <span class="file-name">Choose a file...span>
                <label for="file-upload">Browse<input type="file" 
                    id="file-upload" name="uplodedFile">label>
            div>
            <input type="submit" name="uploadBtn" value="Upload"/>
        form>
    div>

session_start();
$msg = null;
if($_SERVER["REQUEST_METHOD"] == "POST"){
    if(isset($_POST['uploadBtn']) && $_POST['uploadBtn'] == 'Upload'){
          if(isset($_FILES['uplodedFile']) && !empty($_FILES['uplodedFile']['name'])){
              $msg = 'Done.';
          }else{
                 $msg = 'please chose a file';
          }
    }    
}
$_SESSION['msg'] = $msg;
header("location: uploader.php");

سلام،

اتریبیوت enctype="mutipart/form-data" رو برای آپلود فایل به تگ فرم اضافه کنید.

این تاپیک هم در موردش صحبت شده.

محسن موحد ۲۳ اسفند ۱۴۰۱، ۱۰:۰۲