Got error for red line. Can anyone help me on this ?

Discussion in 'Web Design' started by Picole, Feb 4, 2020.

to remove all ads.
Tags:
  1. Picole

    Picole New Member

    Messages:
    1
    <?php
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    include("dbconfig.php");

    $act = $_REQUEST['act'];
    $id = $_POST['id'];

    if(isset($_POST['btn-upload']))
    {
    $Name_PUDC = $_POST['Name_PUDC'];
    $warganegara = $_POST['warganegara'];
    $NRIC_PUDC = $_POST['NRIC_PUDC'];
    $PhoneNo_PUDC = $_POST['PhoneNo_PUDC'];
    $Email_PUDC = $_POST['Email_PUDC'];
    $Venue = $_POST['Venue'];
    $Year_Participation = $_POST['Year_Participation'];
    $Product_Name = $_POST['Product_Name'];
    $description = $_POST['description'];

    //$filedesc = $_POST['filedesc'];
    //$file = rand(1000,100000)."-".$_FILES['file']['name'];
    // Count total files
    $countfiles = count($_FILES['file']['name']);

    // Looping all files
    for($i=0;$i<$countfiles;$i++){
    $file = $_FILES['file']['name'][$i];
    $file_loc = $_FILES['file']['tmp_name'][$i];
    $file_size = $_FILES['file']['size'][$i];
    $file_type = $_FILES['file']['type'][$i];

    $folder="files/";
    $target_file = $folder . $file;

    if (file_exists($target_file))
    {
    echo '<script>alert("Sorry, file already exists."); location.replace(document.referrer);</script>';
    }
    // Check file size
    elseif ($file_size > 80000000)
    {
    echo '<script>alert("Sorry, your file size is over limit."); location.replace(document.referrer);</script>';
    } else {

    $new_size = $file_size/1024; // new file size in KB

    //$new_file_name = strtolower($file); // make file name in lower case

    //$final_file=str_replace(' ','-',$new_file_name);

    date_default_timezone_set("Asia/Kuala_Lumpur");
    $submitted_date = date('Y-m-d H:i:s');

    // Upload file
    if(move_uploaded_file($file_loc,$folder.$file))
    {
    $sql="INSERT INTO poyod (Name_PUDC, warganegara, NRIC_PUDC, Phone_PUDC, Email_PUDC, Venue,Year_Participation, Rank, File, Type, Size, Product_Name, description, submitted_date)
    VALUES ('$Name_PUDC', '$warganegara', '$NRIC_PUDC', '$Phone_PUDC','$Email_PUDC', '$Venue', '$Year_Participation','$Rank', '$File', '$file_type, '$file_size', '$Product_Name', '$description', '$submitted_date')";

    mysqli_query($con,$sql) or die (mysqli_error($con));
    ?>
    <script>
    alert('Successfully uploaded');
    window.location.href='poyod_enter.php?success';
    </script>
    <?php
    }
    else
    {
    ?>
    <script>
    alert('Error while uploading file');
    window.location.href='poyod_enter.php?fail';
    </script>
    <?php
    }
    } //end else file exist
    } //end if(isset($_POST['btn-upload']))
    } //end loop
    else if($act == "delete") {
    $id = $_GET['id'];

    $sql2 = "SELECT file FROM tbl_uploads WHERE id= '$id'";
    $rs = mysqli_query($con,$sql2) or die (mysqli_error($con));
    $row = mysqli_fetch_array($rs);

    $sql3 = "DELETE FROM tbl_uploads WHERE id = '$id'";
    unlink("files/".$row['file']); //delete file from folder

    $result = mysqli_query($con,$sql3) or die (mysqli_error($con));
    if($result) {
    echo "<script>alert('SUCCESS!! Record has been deleted.');window.location.href='view.php';</script>";

    }else {

    echo "<script>alert('ERROR!!! Fail to delete record. Please try again.');window.location.href='view.php';</script>";
    }
    }//end if($act == "delete")
    else if(isset($_POST['deletemultiple']))
    {
    $deleteCb = $_POST['filecheckbox'];
    $filename = $_POST['filename'];
    //$files = $filename;
    for($i=0;$i<count($deleteCb);$i++)
    {
    $id = $deleteCb[$i];
    $files = $filename[$i];

    $query = "DELETE FROM tbl_uploads where id= ".$id;
    @unlink("files/".$files);

    /* if ( @unlink ("files/".$files ) ) {
    echo "<script>alert('The file <strong><span style='color:green;'>' . $files . '</span></strong> was deleted!';</script>";
    } else {
    echo "<script>alert('Couldn\'t delete the file <strong><span style='color:red;'>' . $files . '</span></strong>!';</script>";
    }*/


    $result = mysqli_query($con,$query) or die (mysqli_error($con));

    if($result) {
    echo "<script>alert('SUCCESS!! Record(s) has been deleted.');window.location.href='view.php';</script>";

    }else {

    echo "<script>alert('ERROR!!! Fail to delete record. Please try again.');window.location.href='view.php';</script>";
    }


    }

    }//end if deletemultiple
    //======Download files in ZIP =============
    /*else if(isset($_POST['filecheckbox']))
    {
    $error = ""; //error holder
    */
    else if(isset($_POST['createzip']))
    {
    $post = $_POST;
    $error = ""; //error holder
    $file_folder = "files/"; // folder name to load files in server
    if(extension_loaded('zip'))
    {
    // Checking ZIP extension is available
    if(isset($post['filecheckbox']) and count($post['filecheckbox']) > 0)
    {

    // Checking files are selected
    $zip = new ZipArchive(); // Load zip library
    //$zip_name = time().".zip"; // Zip name
    $zip_name = 'reports.zip';
    if($zip->open($zip_name, ZIPARCHIVE::CREATE)!==TRUE)
    {
    // Opening zip file to load files
    $error .= "* Sorry ZIP creation failed at this time";
    }

    //$fileselect = $_POST['filecheckbox'];
    //$filename = $_POST['filename'];

    /*for($i=0;$i<count($fileselect);$i++)
    {*/
    //$fileselect = $fileselect[$i];
    //$files = $filename[$i];

    foreach($post['filename'] as $file)
    {
    $zip->addFile($file_folder.$file); // Adding files into zip
    }
    //}
    $zip->close();

    if(file_exists($zip_name))
    {
    // push to download the zip
    header('Content-type: application/zip');
    header('Content-Disposition: attachment; filename="'.$zip_name.'"');
    readfile($zip_name);
    // remove zip file is exists in temp path
    unlink($zip_name);
    }

    }else
    $error .= "* Please select file to zip ";

    }else
    $error .= "* You dont have ZIP extension";

    }
    //}
    //end if createzip to download
    ?>
     

Share This Page