4images Forum & Community
4images Issues / Ausgaben => Discussion & Troubleshooting => Topic started by: abdoh2010 on December 12, 2005, 06:00:33 PM
-
after researching i find out that the problem is start with this code inside download.php witch download by buffering witch will not serve me with files more that 200 M,
function get_file_data($file_path) {
global $script_url;
ob_start();
@ob_implicit_flush(0);
@readfile($file_path);
$file_data = ob_get_contents();
ob_end_clean();
if (!empty($file_data)) {
return $file_data;
}
elseif (is_remote_file($file_path)) {
$file_data = get_remote_file($file_path);
}
else {
if (!file_exists($file_path)) {
$file_path = preg_replace("/\/{2,}/", "/", get_document_root()."/".$file_path);
}
if (file_exists($file_path)) {
$file_size = @filesize($file_path);
$fp = @fopen($file_path, "rb");
if ($fp) {
$file_data = @fread($fp, $file_size);
@fclose($fp);
}
}
}
if (empty($file_data)) {
if (ereg("^\/", $file_path)) {
preg_match("/^(http:\/\/[^\/]+)/i", $script_url, $regs);
$script_url = $regs[1];
}
$file_data = get_remote_file($script_url."/".$file_path);
}
return (!empty($file_data)) ? $file_data : 0;
}
so i start a thread on webhostingtalk asking for new code witch may serve me and we finally agrae that the best way is by this code
$handle = fopen("http://www.example.com/", "rb");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
// do something else
}
fclose($handle);
i tried to use it on the funcation but i didnt get it right
so can any one help me with it please ?
-
I see no difference between this code and the original, atleast in the final.
But, you've gave me another idea.
By default 4images read entire file into memory, that allow it to determing exact size of the file (only usefull for remote files) and that is the problem on most servers where memory limit per script is very low.
Now, my idea is to start sending the file content while its still reading it, and theoreticaly, if I'm not misstaken, it should not use as much memory...
I'll do some research on this one and see if it works in reality :D
P.S. I'm using this kind of method to control the download speed :)
-
I'm back with good news :)
My theory above was correct. I've tested it with 700mb file. With default 4images the whole 700mb were loaded into the memory (I was monitoring it with linux "top" command).
After implimenting my code, the memory usage didnt move from normal, and file was successfuly downloaded, and also, the download dialog window poped up instantly, without 10 seconds delay as with default code :)
Before we begin, please note, that zip type downloads and remote files are not supported by these changes, in fact, remote files download might not work any longer (I did not test it)
Open download.php
1) Find:function get_file_data($file_path) {
Replace with:function get_file_data($file_path, $size = 0) {
if ($size)
{
if (!file_exists($file_path) || !$size = filesize($file_path)) return false;
return $size;
}
2) Find: elseif (!$file['file_data'] = get_file_data($file['file_path'])) {
Replace with: elseif (!$file['file_size'] = get_file_data($file['file_path'], 1)) {
3) Find: if ($action == "zip" && !eregi("\.zip$", $file['file_name']) && function_exists("gzcompress") && function_exists("crc32")) {
Insert below: $file['file_data'] = get_file_data($file['file_path']);
4) A few lines below find: $file['file_size'] = strlen($file['file_data']);
Comment it out or simply remove that line.
Note that there are two instances of this line, you need the last instance. below that line should be echo $lang['download_error']."\n<!-- EMPTY FILE PATH //-->";
5) Find:if (!empty($file['file_data'])) {
Comment it out or remove that line.
6) Find: echo $file['file_data'];
Replace with:if (!empty($file['file_data'])) {
echo $file['file_data'];
}
else
{
if ($handle = @fopen($file['file_path'], "rb"))
{
while (!feof($handle))
{
print fread($handle, 512000);
@ob_flush();
@flush();
}
fclose($handle);
}
That's it.
In last step number 512000 represent how many bytes the script will read at ones. (1 KB = 1024 B; 1024 * 500 = 512000 B = 500 KB) You might want to play with that value to find best perfomance.
-
waw waw waw
you really save the day :D
for the zip types download i will disable it any way ,, it will save me resource
and for the remote type ,, all my downloadable files are on my website
i will test it and reply to you,
-
I tried it and it's technically work but I think that there is something wrong with this code
if (!empty($file['file_path'])) {
@set_time_limit(120);
if ($remote_url) {
header("Location: ".$file['file_path']);
exit;
}
elseif (!$file['file_size'] = get_file_data($file['file_path'], 1)) {
?>
<script language="javascript" type="text/javascript">
<!--
window.open('<?php echo $file['file_path']; ?>','imagewindow','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
// -->
</script>
<meta http-equiv="Refresh" content="0; URL=<?php echo $site_sess->url($url, "&"); ?>">
<?php
echo $lang['download_error']."\n<!-- NO FILE DATA / FILE NOT FOUND //-->";
exit;
}
You can test it and see by your self
The default code
http://www.racing4e.com/download.php?image_id=1266
After modify the file
http://www.racing4e.com/download1.php?image_id=1266
-
getting mysql error message, cant test it...:?
maybe you should explain in words what is wrong ;)
[EDIT]
Just tested on a fresh v1.7.1
in Step 1 I've made a mistake in the searched string
in Step 4 I've added more explanation.
and in Step 6 had an extra closing bracket }
[EDIT]
Your file woked just fine on my server...
What path does it show you if you addecho $file['file_path'];
above echo $lang['download_error']."\n<!-- NO FILE DATA / FILE NOT FOUND //-->";
-
sorry for lat
i was out of town
the site is back again if you would like to see the link again
the problem is that refresh is come repetly with out stop and the webpage is this
<script language="javascript" type="text/javascript">
<!--
window.open('http://www.racing4e.com/data/media/51/Riyadh%20Event.zip','imagewindow','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes');
// -->
</script>
<meta http-equiv="Refresh" content="0; URL=">
Error with download
<!-- NO FILE DATA / FILE NOT FOUND //-->
also the new window is open repetly in visable and with out downloading the file
just open new visable window and close it and opening another window again and again
-
do you use download_url for your files? if so, as I mentioned above, this will not work with this code.
-
No
I change the code to the following
elseif (!$file['file_size'] = get_file_data($file['file_path'], 1)) {
?>
<script language="JavaScript" type="text/javascript">
<!--
function beginDownload() {
idl = -1;
idl = location.search.indexOf("idl=n");
if (idl < 0) document.write('<iframe height="0" width="0" src="<?php echo $file['file_path']; ?>"></iframe>');
}
window.onLoad=beginDownload();
//-->
</script>
<noscript>
<iframe height="0" width="0" src="<?php echo $file['file_path']; ?>"></iframe>
</noscript>
<?php
exit;
}
And its work, but I have two problems
The first one is when I click on download button it move me on new Waite page.
the second problem is when I add <meta http-equiv="Refresh" content="0; URL=<?php echo $site_sess->url($url, "&"); ?>">
it give me the same Waite page raptly
I would like when I click on the download button the small download windows come immediately in the same detail page with out moving to Waite page
-
Hi
i have the same problem but with tiff-files that are 10-50mb
V@nos fix helped me
but kan ju help me with zip-files to
i asume that the lightbox start working when the zipbutton starts working
:lol: Urban
-
waiting for you V@no :)
-
abdoh2010, sorry, I cant help you untill I see what kind of file path for the file. As I said, if its web address (aka starts with http://) this code will not work. And what you are trying to do is simply redirect direct to the file - does not need anything "fancy" coding...but then, with your method anyone can leech/hotlink your files from other sites and you wont know about it, untilll end of the month when you see your site's bandwidth usage.
-
after rechecking i find out that the problem is not with your code
the problem is that there is some files on the server that 4images can not find, like thery are not exist, but they are there.
i will try to fix this thing by editing database
-
Dear V@no
using the MOD 'Files Check' that you made solve the rest of my problems
now every thing is ok with the modification that you made for download.php
so i just want to say
thank you :)
-
Hi!!
Does this code is for default download button in detail page??
I have problem with my videos, only 25 mb of them download.
will these codes help me without changing memory limit per script ???????????
hope you undertsand
:cry: :cry:
-
yes on both questions
-
One more question! :wink:
if I use a link of an video for example
http://www.site.com/vidoes/data/media/5/file.wmv
will it also use server memory????
-
it could but it should simply redirect...
-
getting mysql error message, cant test it...:?
maybe you should explain in words what is wrong ;)
[EDIT]
Just tested on a fresh v1.7.1
in Step 1 I've made a mistake in the searched string
in Step 4 I've added more explanation.
and in Step 6 had an extra closing bracket }
[EDIT]
Your file woked just fine on my server...
What path does it show you if you addecho $file['file_path'];
above echo $lang['download_error']."\n<!-- NO FILE DATA / FILE NOT FOUND //-->";
I need this code too, can you explain what exactly was wrong in Step1, 4 and 6? Thank you!!!
-
whatever was wrong, is fixed before I've posted it.
-
any fixes for 1.7.2 or 1.7.3?? as the download.php file in these versions are missing a few lines of code which was in 1.7.1 and were replaced by your patch.