$mapName) { print " # $option = $mapName\n"; $optionsToAlbum[$option++] = $mapId; } print "\nYou choose (press RETURN): "; $c = trim(fgets(STDIN)); $albumId = $optionsToAlbum[$c]; $processedFiles = array(); foreach ($files as $file) { $file = trim($file); $processedFile = do_curl($file, $albumId, $TnetID); $processedFiles[] = $processedFile; } @file_put_contents('results.txt', implode("\r\n", $processedFiles)); @system("start results.txt"); break; case 's': $targetDir = 'C:\\unsorted'; foreach ($files as $file) { $file = trim($file); if (empty($file)) break; $pos = strrpos($file, '.'); if ($pos == -1) { print "ignoring files without file extension\n"; continue; } if (is_dir($file)) { print "ignoring directories\n"; continue; } $ext = strtolower(substr($file, $pos + 1)); if (!is_dir($targetDir)) mkdir($targetDir); if (!is_writable($targetDir)) throw new RuntimeException('targetdir not writable'); $dir = $targetDir . '\\' . $ext; if (!is_dir($dir)) mkdir($dir); if (!is_writable($dir)) throw new RuntimeException('targetdir\extdir not writable'); $targetFile = $dir . '\\' . basename($file); $counter = 2; while (file_exists($targetFile)) { $targetFile = $dir . '\\' . substr(basename($file), 0, -1 * (strlen($ext) + 1)) . sprintf('-%d.', $counter) . $ext; $counter++; } // You need UnixUtils.. $cmd = 'mv '.escapeshellarg($file) . ' ' . escapeshellarg($targetFile); print "executing: " . $cmd . "\n"; system($cmd); } break; case 'c': chdir(dirname(array_pop($files))); print "launching prompt.. you may close this window..\n"; system('start cmd.exe >NUL 2>&1 &'); $nopause = true; break; } } catch (RuntimeException $ex) { print_r($ex); @unlink('selected_files.txt'); } print "Done.... "; if ( ! $nopause) system("pause"); function get_albums_curl($TnetID) { $url = 'https://secure.tweakers.net/my.tnet/fotoalbum'; $strCookie = 'TnetID=' . $TnetID . '; path=/'; $curl = curl_init($url); curl_setopt( $curl, CURLOPT_COOKIE, $strCookie ); curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt( $curl, CURLOPT_VERBOSE, 1 ); $strResponse = curl_exec( $curl ); curl_close($curl); $matches = array(); preg_match_all('/\?map=([0-9]*)">([^<]*)<\/a>/', $strResponse, $matches); $result = array(); foreach ($matches[1] as $index => $mapId) { $mapName = $matches[2][$index]; $result[$mapId] = $mapName; } return $result; } function get_last_img($file, $albumId, $TnetID) { $strCookie = 'TnetID=' . $TnetID . '; path=/'; $url2 = 'https://secure.tweakers.net/my.tnet/fotoalbum/?map=' . $albumId; $curl = curl_init($url2); curl_setopt( $curl, CURLOPT_COOKIE, $strCookie ); curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt( $curl, CURLOPT_VERBOSE, 0 ); $strResponse = curl_exec( $curl); $lines = explode("\n", trim($strResponse)); $catchedFile = "***failed upload: $file***"; foreach ($lines as $line) { if (strpos($line, 'photoAlbumThumb boxCorner3') !== FALSE) { $matches = array(); if (preg_match('/href="([^"]*)"/', $line, $matches) === 1) { $catchedFile = str_replace('&', '&', $matches[1]); break; } } } curl_close($curl); return $catchedFile; } function do_curl($file, $albumId, $TnetID) { $url = 'https://secure.tweakers.net/my.tnet/fotoalbum/?action=upload'; $strCookie = 'TnetID=' . $TnetID . '; path=/'; $a = get_last_img($file, $albumId, $TnetID); // The upload request $curl = curl_init($url); $data = array( 'titel[1]' => '', 'omschrijving[1]' => '', 'afbeelding[1]' => '@' . $file, 'map' => $albumId ); curl_setopt( $curl, CURLOPT_COOKIE, $strCookie ); curl_setopt( $curl, CURLOPT_POST, 1); curl_setopt( $curl, CURLOPT_POSTFIELDS, $data); curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 ); curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt( $curl, CURLOPT_VERBOSE, 1 ); $strResponse = curl_exec( $curl ); curl_close($curl); // Get link to last uploaded image.., and lets hope that is the correct one.. $b = get_last_img($file, $albumId, $TnetID); if ($a == $b) { return "***failed upload: $file"; } return $b; } ?>