0

okay so i am upload files, they have encrypted names once uploaded, the thing is i want to compress them so when a link is reached it downloads instead of displaying

<?php $fileName = $_FILES["file1"]["name"]; // The file name $fileTmpLoc = $_FILES["file1"]["tmp_name"]; // File in the PHP tmp folder $fileType = $_FILES["file1"]["type"]; // The type of file it is $fileSize = $_FILES["file1"]["size"]; // File size in bytes $fileErrorMsg = $_FILES["file1"]["error"]; // 0 for false... and 1 for true if (!$fileTmpLoc) { // if file not chosen echo "ERROR: Please browse for a file before clicking the upload button."; exit(); } $servername = "localhost"; $username = "#"; $password = "#"; $dbname = "#"; function generateRandomString($length = 8) { $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $charactersLength = strlen($characters); $randomString = ''; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; } return $randomString; } $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $extension = pathinfo($fileName, PATHINFO_EXTENSION); $string69 = generateRandomString(); $date = date("l") . "_" . date("d/m/Y"); $encyptstring = $string69 . "." . $extension; if(move_uploaded_file($fileTmpLoc, "upload/VEMWdk/$string69.$extension")){ } else { echo "upload failed :( please contact iHaveDeBestName"; } ?> 

in function move_upload_file instead of having the original '$extention' i would like it to be compressed into a .zip file so it would be like if i uploaded a text file it would save into the upload folder as {randomString}.zip and inside that zip would be the text file.

i have tried other method but all it does is replace files in the zip, i would like to create new zips for each file uploaded

please ignore the sqldB connection, that is going to be used for logging uploads

8
  • sorry for the double sentance at the top Commented Aug 21, 2018 at 10:25
  • Hi, but I dont see any attempt to zip anything, or am I missing something Commented Aug 21, 2018 at 10:27
  • 2
    If you show you r attempts to ZIP the file, someone will probably spot the issue in no time. Rather than showing no attempt which makes the question look like you want the code all written by someone else Commented Aug 21, 2018 at 10:28
  • 1
    Icepick, you should first read the manual on php.net/manual/en/refs.compression.php and only then, if you still have issues implementing your code, ask here. Commented Aug 21, 2018 at 10:35
  • Hi upload files, I am human Commented Aug 21, 2018 at 10:37

1 Answer 1

2
$zip = new ZipArchive(); $filename = "./test112.zip"; //Your Zip File with path if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) { exit("cannot open <$filename>\n"); } $zip->addFile("{your_uploaded_file_with_path}"); // uploaded file $zip->close(); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.