Linked Questions

Popular Questions

uploading files to a folder is not Working

Asked by At

I have a problem with my code. The function MOVE_UPLOADED_FILE is not adding the file to the destiny folder. It inserts the name to the database correctly but the folder still empty. I'm not experienced on uploading files so... I hope you can help me.

<?php
// configuration
include('../connect.php');

// new data
$id = $_POST['memi'];
$a = $_POST['code'];
$z = $_POST['gen'];
$b = $_POST['name'];
$c = $_POST['exdate'];
$d = $_POST['price'];
$e = $_POST['kategori'];
$f = $_POST['qty'];
$g = $_POST['o_price'];
$h = $_POST['profit'];
$i = $_POST['date_arrival'];
$j = $_POST['sold'];
$nama_file = $_POST['namaFile'];

    if (! empty($_FILES['namaFile']['tmp_name'])) {
    $nama_file = $_FILES['namaFile']['name'];
    $nama_file = stripslashes($nama_file);
    $nama_file = str_replace("'","",$nama_file);
    $nama_file = str_replace(" ","-",$nama_file);
    $nama_file = $a.".".$nama_file;
    move_uploaded_file($_FILES['namaFile']['tmp_name'], "images/".$nama_file);
}
else {

    echo "error";
}
// query
$sql = "UPDATE products 
    SET product_code=?, gen_name=?, product_name=?, expiry_date=?, price=?,kd_kategori=?, qty=?, o_price=?, profit=?, date_arrival=?, qty_sold=?,file_gambar=?
WHERE product_id=?";
$q = $db->prepare($sql);
$q->execute(array($a,$z,$b,$c,$d,$e,$f,$g,$h,$i,$j,$nama_file,$id));
header("location: products.php");

?>

Related Questions