how to convert file in zip and at a time store in mysql data with php (dynamically) I make a form in php where i want upload image in database but i want first it's convert in zip and after that store in mysql database how can do this............ plz help me it's urgent plzzzzzzzzzzzzzzzz thanks......................
You can try following codes: $temp_dir = './'; $zip_file = $temp_dir . uniqid() . '.zip'; $image_file = $_FILES['file']['tmp_name']; $image_name = basename($image_file); $zip = new ZipArchive(); if ($zip->open($zip_file, ZIPARCHIVE::CREATE) !== TRUE) { exit("cannot open <$filename>\n"); } $zip->addFile($image_file, $image_name); $zip->close(); $db = mysql_connect("server", "username", "password"); mysql_select_db("database", $db) or die(mysql_errno() . ": " . mysql_error() . "<br>"); $data = addslashes(fread(fopen($zip_file, "r"), filesize($zip_file))); $sql = "INSERT INTO tbl_Images "; $sql .= "(data, filename) "; $sql .= "VALUES ('$data', '$image_name')"; $result = mysql_query($sql, $db); mysql_free_result($result); Code (markup):