macos — не могу загрузить изображения php xampp на mac

Я не могу загрузить изображение в папку, я использую xampp на Mac

<?php
include("../../function/connection.php");
include("../../function/helper.php");$nama_barang = $_POST['nama_barang'];
$kategori_id = $_POST['kategori_id'];
$spesifikasi = $_POST['spesifikasi'];
$status = $_POST['status'];
$button = $_POST['button'];
$harga = $_POST['harga'];
$stok = $_POST['stok'];

$nama_file = $_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"], "../../images/barang/" .$nama_file);

if($button == "Add"){
mysqli_query($connect, "INSERT INTO barang (nama_barang, kategori_id, spesifikasi, gambar, harga, stok, status) VALUES ('$nama_barang', '$kategori_id', '$spesifikasi', '$nama_file', '$harga', '$stok', '$status')");

?>

этот тег HTML-формы.

<form action="<?php echo BASE_URL."module/barang/action.php?barang_id=$barang_id"; ?>" method="POST" enctype='multipart/form-data'>

<div class="element-form">
<label>Kategori</label>
<span>
<select name="kategori_id">
<?php
$queryKategori = mysqli_query ($connect, "SELECT kategori_id, kategori FROM kategori WHERE status='on' ORDER BY kategori ASC");
while ($row=mysqli_fetch_assoc($queryKategori)) {
if ($kategori_id == $row['kategori_id']) {
echo "<option value='$row[kategori_id]' selected='true'>$row[kategori]</option>";
}
echo "<option value='$row[kategori_id]'>$row[kategori]</option>";
}
?>
</select>
</span>
</div>

<div class="element-form">
<label>Nama Barang</label>
<span><input type="text" name="nama_barang" value="<?php echo $nama_barang; ?>" /></span>
</div>

<div class="element-form">
<label>Spesifikasi</label>
<span>
<textarea name="spesifikasi"><?php echo "$spesifikasi";?></textarea>
</span>
</div>

<div class="element-form">
<label>Stock</label>
<span><input type="text" name="stok" value="<?php echo $stok; ?>" /></span>
</div>

<div class="element-form">
<label>Harga</label>
<span><input type="text" name="harga" value="<?php echo $harga; ?>" /></span>
</div>

<div class="element-form">
<label>Gambar Produk <?php echo $keterangan_gambar;?></label>
<span>
<input type="file" name="file"/><?php echo $gambar;?>
</span>
</div>

<div class="element-form">
<label>Status</label>
<span>
<input type="radio" name="status" value="on" <?php if($status == "on"){ echo "checked='true'"; } ?> /> On
<input type="radio" name="status" value="off" <?php if($status == "off"){ echo "checked='true'"; } ?> /> Off
</span>
</div>

<div class="element-form-add">
<span><input type="submit" name="button" value="<?php echo $button; ?>" /></span>
</div>

</form>

-2

Решение

Вы можете попытаться установить try catch для проверки исключений в исключении файла загрузки файла

Вот пример кода о try-catch

try {
//throw exception if can't move the file
if (!move_uploaded_file($_FILES["file"]["tmp_name"], "../../images/barang/" .$nama_file)) {
throw new Exception('Could not move file');
}

//do some more things with the file which may also throw an exception
//...

//ok if got here
echo "Upload Complete!";
} catch (Exception $e) {
die ('File did not upload: ' . $e->getMessage());
}
0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector