I am new to PHP and here is my dilemma. I am trying to add to my site a feature that allows users to select a set of images in Flash (AS3) click a button and hav开发者_运维知识库e my server create a zip file of all the images for them to download.
I have already wrote my code in flash and crated my php script and tested it on my localhost and everything works great. But when I upload the same files to my sever no zip files are created. Below is the code for both my flash and for my php. Any help or tips would be appreciated I am struggling over her.
Localhost server is using 5.2.17 and so if my Server hosted on 1&1
Flash Code To Send Info to PHP
function MakeZip():void
{
var variables:URLVariables = new URLVariables();
//variables.Image1=img1;
variables.ImageList=OrderItems;
variables.Name= zipName_txt.text + ".zip";
variables.FileComplete="File Created";
var request:URLRequest = new URLRequest();
request.url="ArrayTest.php";
request.data=variables;
var loader:URLLoader = new URLLoader();
loader.load(request);//sends the request
//when the request is done loading, it goes to the completeWriting function
loader.addEventListener(Event.COMPLETE, completeWriting);
loader.addEventListener(IOErrorEvent.IO_ERROR, error);
function completeWriting(event:Event):void
{
info_txt.text = "File Created";
}
function error(e:IOErrorEvent):void
{
info_txt.text = "There was an error. Please try again later.";
}
}
PHP to create file
<?PHP
$zipName= $_GET['Name'];
$Order= $_GET['ImageList'];
$fileList = explode('|',$Order);
$ZipComplete = $_GET['FileComplete'];
// create object
$zip = new ZipArchive();
// open archive
if ($zip->open($zipName, ZIPARCHIVE::CREATE) !== TRUE) {
die ("Could not open archive");
}
// add files
foreach ($fileList as $f) {
$zip->addFile($f) or die ("ERROR: Could not add file: $f");
print false;
}
// close and save archive
$zip->close();
//writeVariable( "ZipComplete", $ZipComplete);
echo "FileComple=" . $ZipComplete;
?>
Thank you all for your tips and hints. After hours of trying different things I found the mistake was in my flash code. On my localhost it ignores capitalization for file names. On my server however it does not ignore it. I had in my flash file image1.jpg but the file name is actually Image1.jpg. Glad I found it bit it is so frustrating how a little thing like that made it not work.
is there any error response returned from you php script? please make sure the zip file save path on server is correct and have write access
This is because code is running as "nobody" on server. This user would not have write access to anywhere except /tmp .
Add following code, this should work:
<?PHP
$zipName= $_GET['Name'];
$Order= $_GET['ImageList'];
$fileList = explode('|',$Order);
$ZipComplete = $_GET['FileComplete'];
// create object
$zip = new ZipArchive();
$zipName = "/tmp/" + $zipName;
// open archive
if ($zip->open($zipName, ZIPARCHIVE::CREATE) !== TRUE) {
die ("Could not open archive");
}
$zipName = "/tmp/" + $zipName; is the key part.
精彩评论