İyinet'e Hoşgeldiniz!

Türkiye'nin En Eski Webmaster Forum'una Hemen Kayıt Olun!

Kayıt Ol!

ssh da db yi yedeklemek.

iyinet

Root
Admin
Hosting Firması
Katılım
2 Eylül 2002
Mesajlar
5,028
Reaction score
63
Konum
Sakarya
I have tested this code for remote file (http) on another server and it is working fine.
In some cases, which I do not know why, fopen may not support some http files. Maybe because of redirects (mod_rewite) or proxys behind it.
So my code may not work for you due to an unknown reason.
I will suggest you try for anaother file on another server to see if code works as you wished.
If it does then you need to provide me with more information, without me not able to access that link, I can not reproduce the issue on my site.
 

Desi-Instincts

0
İyinet Üyesi
Katılım
11 Mart 2008
Mesajlar
66
Reaction score
0
I can permit the link access for 5-15 mins. As i see that you are online. Will that do??
 

Desi-Instincts

0
İyinet Üyesi
Katılım
11 Mart 2008
Mesajlar
66
Reaction score
0
I sense there's a problem with the filename thing.... A member of your forum "Angelo" as i previously mentioned had edited the filesplit.php file and added $filename to some lines... and then it was accepting the files (reading it) but the only problem left was to split it accurately into stapled filesizes. I suggest maybe a thought out combination of both the files should work like magic ? Don't you think so ?
 

iyinet

Root
Admin
Hosting Firması
Katılım
2 Eylül 2002
Mesajlar
5,028
Reaction score
63
Konum
Sakarya
Lets get the filename first.
Angelo, could you post the filename line or your code here again?
 

Desi-Instincts

0
İyinet Üyesi
Katılım
11 Mart 2008
Mesajlar
66
Reaction score
0
Here it is ::

<?php
/*
--------------------------------------------------
filesplit.php HJSplit compatiple PHP file splitter
--------------------------------------------------

File name:
filesplit.php
Author:
Umit Tirpan 2007-03-22
Author's Website:
http://forum.iyinet.com/

Description:
This PHP script, splits the files into smaller pieces in binary.
It is compatiple with HJSplit, so you can re-join splitted files using HJSplit's Join utility.
It can split a file up to 999 pieces.

What is the use, why will I use this?
Some webmasters do not have shell access to their websites. This prevents them splitting big files, ie. MySQL backups, into smaller files. Splitting a 200Mb file into 10 x 20Mb file may be easy on webmaster to download in pieces.

How to run:
Make sure your webserver has write permission on the target folder.
Edit variables.
Upload (ftp) this file to your webserver.
For security reason, filename is hardcoded. You can modify code to accept $_GET['file']

Run with your favorite browser.
http://www.<your-web-site>.com/filesplit.php

It is Ok to modify this code and use in/with your applications.

*/




// Edit here (3 variables)
// ---------------------------
// File to split, is its not in the same folder with filesplit.php, full path is required.
$file = "http://desi-instincts.com/Games%20(Latest)%20(2007)/GtASa/GTA%20San%20Andreas.part01.exe";
$filename = "GTA-San-Andreas.part01.exe";


// Target folder. Splitted files will be stored here. Original file never gets touched.
// Do not append slash! Make sure webserver has write permission on this folder.
$targetfolder = 'tmp';

// File size in Mb per piece. For a 200Mb file if piecesize=10 it will result with 20 x 10Mb files
$piecesize = 10;



// Do NOT edit under this line
// ---------------------------
$buffer = 1024*8;
$piece = 1048576*$piecesize;
$current = 0;
$splitnum = 1;
if(!$handle = fopen($file, "rb")) {
die("Unable to open $file.<br>Make sure you edited filesplit.php correctly!<br>\n");
}
$piece_name = $targetfolder.'/'.$filename.'.'.str_pad($splitnum, 3, "0", STR_PAD_LEFT);
$fw = fopen($piece_name,"w");
echo "Splitting $file into $piecesize Mb files (last piece may be smaller in size) ...<br>\n";
echo "$piece_name <br>\n";
while (!feof($handle)) {
if($current < $piece) {
if(fwrite($fw, fread($handle, $buffer))) {
$current += $buffer;
} else {
die("filesplit.php is unable to write to current folder.<br>I think it does not have write permission!<br>Try chmod +w folder<br>\n");
}
} else {
fclose($fw);
$current = 0;
$splitnum++;
$piece_name = $targetfolder.'/'.$filename.'.'.str_pad($splitnum, 3, "0", STR_PAD_LEFT);
echo "$piece_name <br>\n";
$fw = fopen($piece_name,"w");
}
}
fclose($fw);
fclose($handle);
echo "Done! <br>\n"
?>
 

Angelo

0
İyinet Üyesi
Katılım
13 Aralık 2004
Mesajlar
9,603
Reaction score
111
Konum
AZ
$piece_name = $targetfolder.'/'.$filename

When you use $file there and $file is not in the current path, it appends a relative path so it was not working. (ie: tmp/http://www........file.zip so i made another variable just with the filename so it becomes tmp/file.zip )
 

iyinet

Root
Admin
Hosting Firması
Katılım
2 Eylül 2002
Mesajlar
5,028
Reaction score
63
Konum
Sakarya
$piece_name = $targetfolder.'/'.$filename

When you use $file there and $file is not in the current path, it appends a relative path so it was not working. (ie: tmp/http://www........file.zip so i made another variable just with the filename so it becomes tmp/file.zip )

@Angelo
I see, that was a problem with 1st version.
This version hadles remote files with basename() function, so it should not be an issue.

@Desi-Instincts
If you see your error message, it is nothing to do with target folder, it is an issue with the file/link not being able to be opened.
 

iyinet

Root
Admin
Hosting Firması
Katılım
2 Eylül 2002
Mesajlar
5,028
Reaction score
63
Konum
Sakarya
Ok, I guess I found the source of the problem.
Give me 5 minutes to fix the code.
 

Desi-Instincts

0
İyinet Üyesi
Katılım
11 Mart 2008
Mesajlar
66
Reaction score
0
Im waiting for replies like a god's verdict. !! Anyway, for now i would like to (till any permanent solution is not found out) the earlier corrected script by Angelo which apparently created "some" files with random filesizes, i somehow created partitions of 80-90 MB with a file size of 150MB in filescript.php, now i want to query will "these" files work for me as a temporary solution?

As in will it get / is it recombinable with HJsplit ?

Edit : oops didnt notice your post. Waiting for reply. Heartbeat at 200... over and out !!
 

iyinet

Root
Admin
Hosting Firması
Katılım
2 Eylül 2002
Mesajlar
5,028
Reaction score
63
Konum
Sakarya
Hopefully this will do it:

PHP:
<?php
/*
 --------------------------------------------------
 filesplit.php HJSplit compatiple PHP file splitter
 --------------------------------------------------
 
 File name: 
	filesplit.php                
 Author: 
	Umit Tirpan 2007-03-22          
	Umit Tirpan 2008-03-12 [remote file support added]         
 Author's Website: 
	http://forum.iyinet.com/

 Description:
	This PHP script, splits the files into smaller pieces in binary.
	It is compatiple with HJSplit, so you can re-join splitted files using HJSplit's Join utility.
	It can split a file up to 999 pieces.

 What is the use, why will I use this?
	Some webmasters do not have shell access to their websites. This prevents them splitting big files, ie. MySQL backups, into smaller files. Splitting a 200Mb file into 10 x 20Mb file may be easy on webmaster to download in pieces. 
 
 How to run:
	Make sure your webserver has write permission on the target folder.
	Edit variables. 
	Upload (ftp) this file to your webserver.
	For security reason, filename is hardcoded. You can modify code to accept $_GET['file']

 Run with your favorite browser.
	http://www.<your-web-site>.com/filesplit.php
 Or run on shell (ie. ssh)
	php filesplit.php

 It is Ok to share and modify this code and use in/with your applications. No restrictions.

 */




// ---------------------------
// Edit here (3 variables)
// ---------------------------

// File to split, is its not in the same folder with filesplit.php, full path is required.
$filename = "my-big-file.zip"; 

// Target folder. Splitted files will be stored here. Original file never gets touched.
// Do not append slash! Make sure webserver has write permission on this folder.
$targetfolder = '/tmp';

// File size in Mb per piece. For a 200Mb file if piecesize=10 it will result with 20 x 10Mb files
$piecesize = 10;



// ---------------------------
// Do NOT edit under this line
// ---------------------------

$buffer = 1024*8;
$piece = 1048576*$piecesize;
$current = 0;
$splitnum = 1;
if(!$handle = fopen($filename, "rb")) {
	die("Unable to open $filename for read! Make sure you edited filesplit.php correctly!<br>\n");
}

$base_filename = basename($filename);

$piece_name = $targetfolder.'/'.$base_filename.'.'.str_pad($splitnum, 3, "0", STR_PAD_LEFT);
if(!$fw = fopen($piece_name,"w")) {
	die("Unable to open $piece_name for write. Make sure target folder is writeable.<br>\n");
}
echo "Splitting $base_filename into $piecesize Mb files (last piece may be smaller in size) ...<br>\n";
echo "$piece_name <br>\n";
while (!feof($handle) and $splitnum < 999) {
	if($current < $piece) {
		if(fwrite($fw, fread($handle, $buffer))) {
			$ftell = ftell($handle);
			$current = $ftell%($piece+$buffer);
		} else {
			die("filesplit.php is unable to write to target folder. Target folder may not have write permission! Try chmod +w target_folder<br>\n");
		}
	} else {
		fclose($fw);
		$current = 0;
		$splitnum++;
		$piece_name = $targetfolder.'/'.$base_filename.'.'.str_pad($splitnum, 3, "0", STR_PAD_LEFT);
		echo "$piece_name <br>\n";
		$fw = fopen($piece_name,"w");
	}
}
fclose($fw);
fclose($handle);
echo "Done! <br>\n"
?>
 

Desi-Instincts

0
İyinet Üyesi
Katılım
11 Mart 2008
Mesajlar
66
Reaction score
0
I edited :

// File to split, is its not in the same folder with filesplit.php, full path is required.
$filename = "http://desi-instincts.com/Games%20(Latest)%20(2007)/GtASa/GTA%20San%20Andreas.part01.exe";

// Target folder. Splitted files will be stored here. Original file never gets touched.
// Do not append slash! Make sure webserver has write permission on this folder.
$targetfolder = '/tmp';

// File size in Mb per piece. For a 200Mb file if piecesize=10 it will result with 20 x 10Mb files
$piecesize = 100;


Browser showed after some waiting :

Splitting http://desi-instincts.com/Games (Latest) (2007)/GtASa/GTA San Andreas.part01.exe into 100 Mb files (last piece may be smaller in size) ...
/tmp/GTA%20San%20Andreas.part01.exe.001
/tmp/http://desi-instincts.com/Games%20(Latest)%20(2007)/GtASa/GTA%20San%20Andreas.part01.exe.002

Warning: fopen(/tmp/http://desi-instincts.com/Games%20(Latest)%20(2007)/GtASa/GTA%20San%20Andreas.part01.exe.002) [function.fopen]: failed to open stream: No such file or directory in /mounted-storage/home90b/sub008/sc42254-ESFQ/www/filesplit1.php on line 88

Warning: fwrite(): supplied argument is not a valid stream resource in /mounted-storage/home90b/sub008/sc42254-ESFQ/www/filesplit1.php on line 76
filesplit.php is unable to write to target folder. Target folder may not have write permission!
Try chmod +w target_folder
 

Desi-Instincts

0
İyinet Üyesi
Katılım
11 Mart 2008
Mesajlar
66
Reaction score
0
YOU ARE THE LORD.... THANKS A ZILLION..

Just one thing for future users of your script. . . Please in your provided script ::

Instead of :
// Do not append slash! Make sure webserver has write permission on this folder.
$targetfolder = '/tmp';

Use :
// Do not append slash! Make sure webserver has write permission on this folder.
$targetfolder = 'tmp';

It did not work initially, but i just removed the slash and it worked.
 

iyinet

Root
Admin
Hosting Firması
Katılım
2 Eylül 2002
Mesajlar
5,028
Reaction score
63
Konum
Sakarya
YOU ARE THE LORD.... THANKS A ZILLION..

Just one thing for future users of your script. . . Please in your provided script ::

Instead of :
// Do not append slash! Make sure webserver has write permission on this folder.
$targetfolder = '/tmp';

Use :
// Do not append slash! Make sure webserver has write permission on this folder.
$targetfolder = 'tmp';

It did not work initially, but i just removed the slash and it worked.

Will do, thanks for the suggestion.
Could you verify: Are your splitted files same size, except the last one?
 

iyinet

Root
Admin
Hosting Firması
Katılım
2 Eylül 2002
Mesajlar
5,028
Reaction score
63
Konum
Sakarya
Where are your target files (100Mb pieces) located under after the split?
/tmp
or
somedir/tmp
??
 

Desi-Instincts

0
İyinet Üyesi
Katılım
11 Mart 2008
Mesajlar
66
Reaction score
0
I cant say exactly same though .....

Here's the detail :
GTA%20San%20Andreas.part01.exe.001 12-Mar-2008 19:53 100M
GTA%20San%20Andreas.part01.exe.002 12-Mar-2008 19:54 100M
GTA%20San%20Andreas.part01.exe.003 12-Mar-2008 19:54 100M
GTA%20San%20Andreas.part01.exe.004 12-Mar-2008 19:54 100M
GTA%20San%20Andreas.part01.exe.005 12-Mar-2008 19:54 3.0M

this way its same but in bytes its different ...
 

Türkiye’nin ilk webmaster forum sitesi iyinet.com'da forum üyeleri tarafından yapılan tüm paylaşımlardan; Türk Ceza Kanunu’nun 20. Maddesinin, 5651 Sayılı Kanununun 4. maddesinin 2. fıkrasına göre, paylaşım yapan üyeler sorumludur.

Backlink ve Tanıtım Yazısı için iletişime geçmek için Skype Adresimiz: .cid.1580508955483fe5

Üst