What is "->"
Posted: Tue May 04, 2010 12:12 pm
I'm trying to make a website where people can download a folder of pictures off of my server.
I went online and found this tutorial on how to zip up files and then force download them. I was excited with how well this fit my problem and typed up this php document:
Upon running this code, the browser just prints out everything after the first "->" as if it's just text.
What exactly does "->" do and why does it seem to close my php tag?
Googleing doesn't return much information. I could only find that it calls functions or parameters of an object which if fine but doesn't really help me.
I went online and found this tutorial on how to zip up files and then force download them. I was excited with how well this fit my problem and typed up this php document:
Code: Select all
<html>
<body>
<?php
function getfiles() {
$dir = "uploads/";
$zipname = "download.zip";
$pictures;
//compiles a list of all the files in the uploads foulder
if(is_dir($dir)){
if($dh = opendir($dir)) {
$i = 0;
while(($file = readdir($dh)) !== false) {
$pictures[$i] = $file;
$i++;
}
closedir($dir);
}
}
zipFilesAndDownload($pictures,$zipname,$dir);
}
//function to zip and force download the files using PHP
function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
{
//create the object
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
$res = $zip->open($archive_file_name, ZIPARCHIVE::CREATE);
if ($res===FALSE) {
exit("cannot open" . $archive_file_name . "\n");
}
//add each files of $file_name array to archive
foreach($file_names as $files)
{
$zip->addFile($file_path.$files,$files);
}
$zip->close();
//then send the headers to foce download the zip file
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");
readfile("$archive_file_name");
exit;
}
getfiles();
?>
</body>
</html> What exactly does "->" do and why does it seem to close my php tag?
Googleing doesn't return much information. I could only find that it calls functions or parameters of an object which if fine but doesn't really help me.