我試圖隱藏圖像框,直到文件被設置在我的文件上傳代碼中。現在它顯示$preview
圖像框,無論是否已設置文件。if(isset)隱藏一個元素直到它被設置爲
我在做什麼錯?
<form action="" method="POST" enctype="multipart/form-data">
Change your profile picture <br><input type="file" name="file" class="inputbarfile" onchange="readURL(this);">
<?php
$preview_file = '<input type="file" name="file" class="inputbarfile" onchange="readURL(this);">';
$preview = '<img width="300px" height="200px" id="file" src="#" alt="your image">';
if (empty($preview_file)) {
'';
} else {
echo $preview;
} ?>
<input type="submit" name="create" value="Upload">
</form>
好,'$ preview_file'顯然會永遠是空的,因爲你明確地將一個字符串分配給它只有兩行。 – arkascha
我認爲你對什麼運行在哪裏感到困惑。這是不可能直接使用PHP的。 PHP在服務器上運行,而不是在客戶端上運行。當你看到這個頁面時,PHP已經完成了(給予或帶走)。動態頁面間交互需要JS完成(需要時使用AJAX)。 –
它會這樣做,你正在設置'$ preview_file',然後它下面的2行檢查是否爲空,它不會是。 – Blinkydamo