Re: [PHP/OOP] 4chan image downloader V2
Re: [PHP/OOP] 4chan image downloader V2
Rasta your script works fine :)
idk whats up with mine though.
I've edited everything i need to but check it out:
http://rapidwind.net/4chan/4chan.php
When you enter the URL of the thread it doesn't show any pictures it only shows the download button.
here is what I have in the script:
(File permissions are at 755)
PHP Code:
<?php
class image_downloader {
public $url;
protected function get_source() {
if(($source = @file_get_contents($this->url)) == false) {
die("Could not open thread.");
}
return $source;
}
protected function get_file_link() {
$source = $this->get_source();
preg_match_all("/File :(.*?)\<blockquote\>/is", $source, $matches_image);
while($i < count($matches_image[1])) {
preg_match("/\<a href\=\\\"(.*?)\\\" target\=/is", $matches_image[0][$i], $images_array[$i]);
$i ++;
}
return $images_array;
}
public function get_images() {
$a_images = $_POST['amount'];
$i = 1;
while($i < $a_images) {
if(isset($_POST["image_$i"])) {
$images_array[$i] .= $_POST["image_$i"];
}
$i ++;
}
return $images_array;
}
public function save_file() {
$images_array = $this->get_images();
$i = 1;
$errors = 0;
while($i < count($images_array)) {
$extension = preg_replace("/.*\./is", "", $images_array[$i]);
if(($handle_external = @fopen($images_array[$i], "r"))) {
while($line = fread($handle_external, 8192)) {
$file .= $line;
}
//Change the directory between quotes to change the directory the image will be downloaded to.
while(($handle_internal = fopen("./images".rand(0000000000001,9999999999999).".$extension", "x+"))== false)
fclose($handle_external);
fwrite($handle_internal, $file);
fclose($handle_internal);
unset($handle_external, $line, $file, $handle_internal);
} else {
$errors ++;
}
$i ++;
}
echo $errors . " image(s) not saved.<br/><br/><a href='".$_SERVER['PHP_SELF']."'><<back</a>";
}
}
class display_images extends image_downloader {
public $url;
private function get_thumbs() {
$source = $this->get_source();
preg_match_all("/File :(.*?)\<blockquote\>/is", $source, $matches_image);
while($i < count($matches_image[1])) {
preg_match("/img src=([a-z0-9:\/\.]*)/is", $matches_image[0][$i], $thumbs_array[$i]);
$i ++;
}
return $thumbs_array;
}
public function d_img_form() {
$thumbs_array = $this->get_thumbs();
$images_array = $this->get_file_link();
$i = 1;
echo '<form name="image_form" method="post" action="4chan.php">';
echo "\n";
echo '<table cellspacing ="5" border ="0" align="center">';
echo "\n";
while($i < count($thumbs_array)) {
$thumbs .= "<td><div style='width:130px; height:130px; background-color:#000000;' align='center'><input type='checkbox' checked='checked' name='image_$i' value='".$images_array[$i][1]."' style='float:right;'/><a href='".$images_array[$i][1]."' target='_blank'><img src='".$thumbs_array[$i][1]."' alt='Thumbnail $i' style='max-height:115px;' border='0'/></a></div></td>\n";
if(($i % $_POST['images_row'] == 0) || (count($thumbs_array) - $i == 1)) {
echo "<tr>\n";
echo $thumbs;
echo "</tr>\n";
unset($thumbs);
}
$i ++;
}
echo "</table>";
echo "<input type='hidden' name='amount' value='".count($thumbs_array)."'/>";
echo "\n <br/> \n";
echo '<div align="center"><input type="submit" name="download" value="download"/></div>';
echo '</form>';
}
}
set_time_limit(0);
ini_set("max_execution_time", "0");
if(!isset($_POST['get_thread']) && !isset($_POST['download'])) {
?>
<form method="post" action="<?=$_SERVER['PHP_SELF'];?>">
Link to thread:<br/>
<input type="text" size="55" name="link" />
<br/>
Amount of images per row
<select name="images_row">
<option value="10">10</option>
<option value="9">9</option>
<option value="8">8</option>
<option value="7">7</option>
<option value="6">6</option>
<option value="5">5</option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
<br/>
<input type="submit" value="submit" name="get_thread" />
</form>
<?php
} else if(!isset($_POST['download'])) {
$display = new display_images();
$display -> url = $_POST['link'];
$display -> d_img_form();
} else {
$downloader = new image_downloader();
$downloader -> save_file();
}
?>
Re: [PHP/OOP] 4chan image downloader V2
Quote:
Originally Posted by
Carter
Rasta your script works fine :)
idk whats up with mine though.
I've edited everything i need to but check it out:
http://rapidwind.net/4chan/4chan.php
When you enter the URL of the thread it doesn't show any pictures it only shows the download button.
here is what I have in the script:
(File permissions are at 755)
PHP Code:
<?php
class image_downloader {
public $url;
protected function get_source() {
if(($source = @file_get_contents($this->url)) == false) {
die("Could not open thread.");
}
return $source;
}
protected function get_file_link() {
$source = $this->get_source();
preg_match_all("/File :(.*?)\<blockquote\>/is", $source, $matches_image);
while($i < count($matches_image[1])) {
preg_match("/\<a href\=\\\"(.*?)\\\" target\=/is", $matches_image[0][$i], $images_array[$i]);
$i ++;
}
return $images_array;
}
public function get_images() {
$a_images = $_POST['amount'];
$i = 1;
while($i < $a_images) {
if(isset($_POST["image_$i"])) {
$images_array[$i] .= $_POST["image_$i"];
}
$i ++;
}
return $images_array;
}
public function save_file() {
$images_array = $this->get_images();
$i = 1;
$errors = 0;
while($i < count($images_array)) {
$extension = preg_replace("/.*\./is", "", $images_array[$i]);
if(($handle_external = @fopen($images_array[$i], "r"))) {
while($line = fread($handle_external, 8192)) {
$file .= $line;
}
//Change the directory between quotes to change the directory the image will be downloaded to.
while(($handle_internal = fopen("./images".rand(0000000000001,9999999999999).".$extension", "x+"))== false)
fclose($handle_external);
fwrite($handle_internal, $file);
fclose($handle_internal);
unset($handle_external, $line, $file, $handle_internal);
} else {
$errors ++;
}
$i ++;
}
echo $errors . " image(s) not saved.<br/><br/><a href='".$_SERVER['PHP_SELF']."'><<back</a>";
}
}
class display_images extends image_downloader {
public $url;
private function get_thumbs() {
$source = $this->get_source();
preg_match_all("/File :(.*?)\<blockquote\>/is", $source, $matches_image);
while($i < count($matches_image[1])) {
preg_match("/img src=([a-z0-9:\/\.]*)/is", $matches_image[0][$i], $thumbs_array[$i]);
$i ++;
}
return $thumbs_array;
}
public function d_img_form() {
$thumbs_array = $this->get_thumbs();
$images_array = $this->get_file_link();
$i = 1;
echo '<form name="image_form" method="post" action="4chan.php">';
echo "\n";
echo '<table cellspacing ="5" border ="0" align="center">';
echo "\n";
while($i < count($thumbs_array)) {
$thumbs .= "<td><div style='width:130px; height:130px; background-color:#000000;' align='center'><input type='checkbox' checked='checked' name='image_$i' value='".$images_array[$i][1]."' style='float:right;'/><a href='".$images_array[$i][1]."' target='_blank'><img src='".$thumbs_array[$i][1]."' alt='Thumbnail $i' style='max-height:115px;' border='0'/></a></div></td>\n";
if(($i % $_POST['images_row'] == 0) || (count($thumbs_array) - $i == 1)) {
echo "<tr>\n";
echo $thumbs;
echo "</tr>\n";
unset($thumbs);
}
$i ++;
}
echo "</table>";
echo "<input type='hidden' name='amount' value='".count($thumbs_array)."'/>";
echo "\n <br/> \n";
echo '<div align="center"><input type="submit" name="download" value="download"/></div>';
echo '</form>';
}
}
set_time_limit(0);
ini_set("max_execution_time", "0");
if(!isset($_POST['get_thread']) && !isset($_POST['download'])) {
?>
<form method="post" action="<?=$_SERVER['PHP_SELF'];?>">
Link to thread:<br/>
<input type="text" size="55" name="link" />
<br/>
Amount of images per row
<select name="images_row">
<option value="10">10</option>
<option value="9">9</option>
<option value="8">8</option>
<option value="7">7</option>
<option value="6">6</option>
<option value="5">5</option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select>
<br/>
<input type="submit" value="submit" name="get_thread" />
</form>
<?php
} else if(!isset($_POST['download'])) {
$display = new display_images();
$display -> url = $_POST['link'];
$display -> d_img_form();
} else {
$downloader = new image_downloader();
$downloader -> save_file();
}
?>
Yes, mine has the same error.
Re: [PHP/OOP] 4chan image downloader V2
Quote:
Originally Posted by
Rasta
Yes, mine has the same error.
That's weird lol, when i go on yours it works for me..
Re: [PHP/OOP] 4chan image downloader V2
I think 4chan changed it's source code around a bit because the script doesn't seem to work anymore. I'll try to fix it as soon as possible.
Re: [PHP/OOP] 4chan image downloader V2
Quote:
Originally Posted by
Pieman
I think 4chan changed it's source code around a bit because the script doesn't seem to work anymore. I'll try to fix it as soon as possible.
That would be very much appreciated, as it's alot easier than saving every image one by one. :thumbup1:
Re: [PHP/OOP] 4chan image downloader V2
Yea, I noticed this didn't work a while ago. I'll probably try fixing it later.
Re: [PHP/OOP] 4chan image downloader V2
Updated the first post with the new script. Everything is working as it should now. :):
Re: [PHP/OOP] 4chan image downloader V2
I keep getting 0 image(s) was downloaded even though it displays the images and I check them and everything.
The image link is correct and I have tried everything from an abolute path, to a local path.
Okay scratch that I got it working, any way for this to work after you close the window? That way I don't have to wait indefinitely?
Perhaps integrate http://www.phpclasses.org/browse/package/1277.html a process queue?
Re: [PHP/OOP] 4chan image downloader V2
Quote:
Originally Posted by
TeamColtra
I keep getting 0 image(s) was downloaded even though it displays the images and I check them and everything.
The image link is correct and I have tried everything from an abolute path, to a local path.
Okay scratch that I got it working, any way for this to work after you close the window? That way I don't have to wait indefinitely?
Perhaps integrate
http://www.phpclasses.org/browse/package/1277.html a process queue?
After you press submit, you can close the window and the script will keep running on your web server.