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();
}
?>