PHP Help (loop) 10 Points

Status
Not open for further replies.

Josh

Uber No0b
Messages
394
Reaction score
0
Points
0
Alright, I have this php script that helps me copy files to my server and I need help modding it so I can input a number of times to grab the file from another server (ex 15 times). If this can't be done, just make an infinite loop. This is to make many copies of the same file on the server. I believe this has something to do with php loops, although I have no PHP experience so this is just a guess. I realize there are other ways to do this, but I would like it this way.


edit: offering 20 points instead.

15 points to the person who can do this.

This is the PHP code:

PHP:
<?

C:\htdocs\FOLDER (Windows)
$defaultDest = "/ho/";
$password = "";

// Operating System your SERVER Uses
//1 for Linux. 2 for Windows.
//I'm not sure but I think most Operating Systems other then Windows will use 1.
$os = "1";

//////////////////////////////////////////////
//Do Not Change Below Here////////////////////
//////////////////////////////////////////////

echo "<form method=\"POST\" action=\"$PHP_SELF\">";
echo "<fieldset>\n<legend>Image Upload</legend>\n";
echo "<label for=\"file\">Full path to file to copy</label><br>";
echo "Example: http://www.google.ca/intl/en_ca/images/logo.gif<br>";
echo "<input type=\"text\" name=\"file\" id=\"file\" size=\"35\" tabindex=\"1\" value=\"\"><br>";
echo "<label for=\"new\">New file name</label><br>";
echo "Example: google.gif<br>";
echo "<input type=\"text\" name=\"new\" id=\"new\" size=\"35\" tabindex=\"2\" value=\"\"><br>";
if ($password) {
    echo "<label for=\"password\">Password</label><br>";
    echo "<input type=\"password\" name=\"password\" id=\"password\" size=\"35\" tabindex=\"3\" value=\"\"><br>";
}
echo "<p><input name=\"submit\" type=\"submit\" id=\"submit\" value=\"submit\"></p>";
echo "</fieldset>\n</form>";

$submit = $_POST['submit'];
if($submit) {
if($password) {
    if ($_POST['password']!=$password) {
        echo "Password incorrect!";
        } else {
        $access = "09023578353";
        }
        } else {
$access = "09023578353";
}


if($access=="09023578353") {

if($os==2) {
    $slash="\\";
} else {
    $slash="/";
}

$file = $_POST['file'];
$newfilename = $_POST['new'];

if($_POST['otherdest']) {
    $dest = $_GET['otherdest'];
} else {
    $dest = $defaultDest;
}

$ds = array($dest, $slash, $newfilename);
$ds = implode("", $ds);

if (file_exists($ds)) {
    echo "File already exists! <br>\n Adding random digits to beginning of filename. <br>\n";
    $ds = array($dest, $slash, rand(0,9999), $newfilename);
    $ds = implode("", $ds);
}

echo "New destination $ds <br>\n";
if (!copy($file, $ds)) {
    echo "Was unable to copy $file <br>\n See if your path and destination are correct. \n";
} else {
    echo "<strong>Copy successful!</strong> \n";
}
}
}

?>
 
Last edited:

Chris Z

Active Member
Messages
5,603
Reaction score
0
Points
36
i believe you will get maybe like 1/4 of a script with 25 points, that's not even close to reasonable for this sort of job
 

Josh

Uber No0b
Messages
394
Reaction score
0
Points
0
Ok 180 points then, Its been a while since I was on the forums, a lot has changed since. 25 points used to be good amount of points.
 
Last edited:

Chris S

Retired
Messages
2,055
Reaction score
1
Points
38
I have no idea if this works

PHP:
<?

C:htdocsFOLDER (Windows)
$defaultDest = "/ho/";
$password = "";

// Operating System your SERVER Uses
//1 for Linux. 2 for Windows.
//I'm not sure but I think most Operating Systems other then Windows will use 1.
$os = "1";

//////////////////////////////////////////////
//Do Not Change Below Here////////////////////
//////////////////////////////////////////////

echo "<form method=\"POST\" action=\"$PHP_SELF\">";
echo "<fieldset>\n<legend>Image Upload</legend>\n";
echo "<label for=\"file\">Full path to file to copy</label><br>";
echo "Example: http://www.google.ca/intl/en_ca/images/logo.gif<br>";
echo "<input type=\"text\" name=\"file\" id=\"file\" size=\"35\" tabindex=\"1\" value=\"\"><br>";
echo "<label for=\"new\">New file name</label><br>";
echo "Example: google.gif<br>";
echo "<input type=\"text\" name=\"new\" id=\"new\" size=\"35\" tabindex=\"2\" value=\"\"><br>";
echo "Upload Files x number of times.<input type=\"text\" name=\"times\" id=\"times\" size=\"3\" tabindex=\"2\" value=\"\"><br>";
if ($password) {
    echo "<label for=\"password\">Password</label><br>";
    echo "<input type=\"password\" name=\"password\" id=\"password\" size=\"35\" tabindex=\"3\" value=\"\"><br>";
}
echo "<p><input name=\"submit\" type=\"submit\" id=\"submit\" value=\"submit\"></p>";
echo "</fieldset>\n</form>";

$submit = $_POST['submit'];
if($submit) {
if($password) {
    if ($_POST['password']!=$password) {
        echo "Password incorrect!";
        } else {
        $access = "09023578353";
        }
        } else {
$access = "09023578353";
}


if($access=="09023578353") {

if($os==2) {
    $slash="\\";
} else {
    $slash="/";
}

$number = $_PST['times'];
$file = $_POST['file'];
$newfilename = $_POST['new'];

$num = '0';

if (($num) != $number){
if($_POST['otherdest']) {
    $dest = $_GET['otherdest'];
} else {
    $dest = $defaultDest;
}

$ds = array($dest, $slash, $newfilename);
$ds = implode("", $ds);

if (file_exists($ds)) {
    echo "File already exists! <br>\n Adding random digits to beginning of filename. <br>\n";
    $ds = array($dest, $slash, rand(0,9999), $newfilename);
    $ds = implode("", $ds);
}

echo "New destination $ds <br>\n";
if (!copy($file, $ds)) {
    echo "Was unable to copy $file <br>\n See if your path and destination are correct. \n";
} else {
    echo "<strong>Copy successful!</strong> \n";
$num ++;
}
}
}
}

?>

it should, but I am at school where there is no server to test it on

if it errors on line 80 or so find this

PHP:
$num ++;

and replace with
PHP:
$num++;
 

Josh

Uber No0b
Messages
394
Reaction score
0
Points
0
there aren't any errors, but the loop isn't working. It only grabs the file once, no matter how many numbers I put in.
 
Status
Not open for further replies.
Top