Create and Download Zip File is printing garbage value on the screen - php

It is a follow up question to my previous post : https://stackoverflow.com/questions/20350947/php-readfile-printing-garbage-value-on-the-screen
I am creating a PHP file and then trying to download it.
What's happening is, When I create and then download, it prints garbage value on the screen.
However, If I just download the same zip file, it works perfectly fine.
My guess is, that the zip file might not be created when it tries to download it ?
Can you please suggest me, where I am going wrong with this?

Related

I just accidentally replaced my whole php code with another file in cPanel - Is there any way I could get that code back?

I was working on response.php file, and I wanted to open another file sample.php so I changed the path & clicked on reopen file :
As it was processing, I accidentally clicked the save code button again - since the file path now had sample.php, (the code still had response file's code in it - as the sample file's code was not loaded till now) it now saved the response file's code in sample file - and somehow it closed the tab itself! So now both the files - response.php and sample.php have the exact same code, and since the tab closed, I can't undo the change in the sample.php file 🤷‍♀️
What should I do to get my sample.php's code back?
I hope you understand my problem..
Any help would be appreciated! Thanks!
You wouldn't have any problem if you had a copy of the files on your local computer before you uploaded them on your server. As far as I know, the sample.php is gone for good.

Cannot download using fpassthru

I'm trying to serve a file for download to a user, and I'm having trouble with fpassthru. The function I'm using to download a file is:
http://pastebin.com/eXDpgUqq
Note that the file is successfully created from a blob, and is in fact the file I want the user to download. The script exits successfully, and reports no errors, but the file is not downloaded. I can't for the life of me think what's wrong.
EDIT: I removed the error suppression from fopen(), but it still reports no error. Somehow the data in the output buffer is never being told to be downloaded by the browser.
I tried your code (without the blob part), and it worked fine. I can download a binary file. Based on my experience, here are something to check:
Has the file been completely saved before you initiate the reading? Check the return value of file_put_contents.
How large is the file? fpassthru reads the whole file into memory. If the file is too large, memory might be insufficient. Please refer to http://board.phpbuilder.com/showthread.php?10330609-RESOLVED-php-driven-file-download-using-fpassthru for more information.
Instead of downloading the file to local server (reading the whole file into server’s memory, and letting the client download the file from the server), you can create an SAS URL, and simply redirect the browser to the URL. Azure will take care of download automatically. You many want to refer to http://blogs.msdn.com/b/azureossds/archive/2015/05/12/generating-shared-access-signature-sas-using-php.aspx for a sample.
I was able to download the file by passing a stream obtained with the Azure API directly to fpassthru, without creating a file. Unfortunately, I can't show the code because it belongs to a project that I have finished working on and the code is no longer available to me.

PHP - Is file being written to?

My mailserver writes to a file every minute, this is fine and I'm happy for it to do that.
However on my WebServer, I want to check if that file is currently being written to and if it isn't, show the user a download link.
Is there any way I can do this..
For example: run a loop that will keep looking until the file is no longer being written to then, show a download link to the file?
I've read about flock() but I don't think this will help as another process / os is actually creating the file!
Your writting script/app/process should write lock file (empty file like filename.lock before it starts writting to main file, and then it shall remove when done. It's regular locking approach but the your script will just need to check if filename.lock is present or not. If it is, then file is being written to.
You can only acquire a read or write lock if no-one else is currently writing. You shouldn't have to do this.
Also, when the user downloads the file it could be the file has changed in the mean time. Are you sure you've got the right mental image of what you want?

PHPWord configuration issue

I am having problem running script of PHPWord.
I am trying to run sample example. Text.php after running it doesn't show anything. I checked it loads class successfully. Documentation.
I would like to able to run script anyone has this problem.
This is what i did -
Downloaded PHPWord_0.6.2_Beta.zip from Download link.
Extracted the zip under htdocs/core/phpword.
Created swap.php and pasted the whole code what was mentioned at Link
Commented, this is it was showing error.
//$myTextElement->setBold();
//$myTextElement->setName('Verdana');
//$myTextElement->setSize(22);
Now i run swap.php file and helloWorld.docx successfully created. You can flag a message if you want in that file. Let me know if you have any query.

How to download files using AppMobi XDK. Can't get it to work

Does anyone know of a way to download a file in appMobi? I have tried force downloading and just opening the file I wish to download, both times, nothing happens.
You can add it to cache. Documentation here.

Categories