Skip to main content
Take question out of title. add tags.
Source Link
rolfl
  • 98.1k
  • 17
  • 220
  • 419

Help me make this code safer and more efficient Recursive Directory Copy

I've been told that my code is horribly-written. It works exactly the way I want it to, but everyone saysI have been told that it needs to be safer and more efficient.

Help me make this code safer and more efficient

I've been told that my code is horribly-written. It works exactly the way I want it to, but everyone says it needs to be safer and more efficient.

Recursive Directory Copy

I've been told that my code is horribly-written. It works exactly the way I want it to, but I have been told that it needs to be safer and more efficient.

Cleaned up title and explanation
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

i have been told my code isent up to date and itent safe can someone help Help me make this code safer and more efficient please?

ok so iveI've been told that my code is horribly written, it-written. It works exactly the way iI want it to, but everyone it sayingsays it needs to be safer and more efficient!.

heres the code: https://gist.github.com/Thorbis/b858c303a8e1452f251eHere's the code.

heresHere's the main phpPHP script tho:

i have been told my code isent up to date and itent safe can someone help me make this safer and more efficient please?

ok so ive been told my code is horribly written, it works exactly the way i want it to but everyone it saying it needs to be safer and more efficient!

heres the code: https://gist.github.com/Thorbis/b858c303a8e1452f251e

heres the main php script tho:

Help me make this code safer and more efficient

I've been told that my code is horribly-written. It works exactly the way I want it to, but everyone says it needs to be safer and more efficient.

Here's the code.

Here's the main PHP script:

Source Link

i have been told my code isent up to date and itent safe can someone help me make this safer and more efficient please?

ok so ive been told my code is horribly written, it works exactly the way i want it to but everyone it saying it needs to be safer and more efficient!

heres the code: https://gist.github.com/Thorbis/b858c303a8e1452f251e

heres the main php script tho:

<?php
$host     = "*******"; // Host firstname
$name     = "*******"; // Mysql userfirstname
$password = "*******!"; // Mysql password
$db_name  = "*******"; // Database firstname
$tbl_name = "users"; // Table firstname
// Connect to server and select database.
mysql_connect("$host", "$username", "$password") or die("cannot connect");
mysql_select_db("$db_name") or die("cannot select DB");
foreach($_POST as &$v)
    $v = mysql_real_escape_string($v);
// Get values from form
$firstname         = $_POST['firstname'];
$lastname          = $_POST['lastname'];
$email             = $_POST['email'];
$resumewebsitename = $_POST['resumewebsitename'];
$resumewebsitename = substr($resumewebsitename, 0, 20);
$website           = 'http://www.thorbis.com/onlineresumes/users/' . $resumewebsitename;
$cell              = $_POST ['cell'];
$overview          = $_POST ['overview'];
$query = mysql_query("SELECT * FROM users WHERE email='$email'");
if(mysql_num_rows($query) != 0)
{
    echo "email already exists";
    // redirect back to form and populate with 
    // data that has already been entered by the user
}
else
 
{
                $dbunames = mysql_query("SELECT * FROM users WHERE website='$website'");
                if (mysql_num_rows($dbunames) > 0) {
                                echo "Sorry That Resume Name Has Been Taken Please Try Again :D";
                } //mysql_num_rows($dbunames) > 0
                else {
                                // function to recursively copy
                                // a directory and its subdirectories
                                function copyRecursive($source, $destination)
                                {
                                                // check if source exists
                                                if (!file_exists($source)) {
                                                                die("'$source' is not valid");
                                                } //!file_exists($source)
                                                if (!is_dir($destination)) {
                                                                mkdir($destination);
                                                } //!is_dir($destination)
                                                // open directory handle
                                                $dh = opendir($source) or die("Cannot open directory '$source'");
                                                // iterate over files in directory
                                                while (($file = readdir($dh)) !== false) {
                                                                // filter out "." and ".."
                                                                if ($file != "." && $file != "..") {
                                                                                if (is_dir("$source/$file")) {
                                                                                                // if this is a subdirectory
                                                                                                // recursively copy it
                                                                                                copyRecursive("$source/$file", "$destination/$file");
                                                                                } //is_dir("$source/$file")
                                                                                else {
                                                                                                // if this is a file
                                                                                                // copy it
                                                                                                copy("$source/$file", "$destination/$file") or die("Cannot copy file '$file'");
                                                                                }
                                                                } //$file != "." && $file != ".."
                                                } //($file = readdir($dh)) !== false
                                                // close directory
                                                closedir($dh);
                                }
                                $source_directory      = "Interactive Resume/";
                                $destination_directory = "users/";
                                copyRecursive($source_directory, $destination_directory);
                                @rename("users/user", "users/" . $resumewebsitename);
                                $emails = ("$email, [email protected]");
                                $to      = $emails;
                                $subject = 'Thorbis | Submit';
                                $message = "<h3 style='color: red;'>This is ALL of your Info That You Inputed I will get back to you ASAP and customly make your website for you :D if i dont email me again at <a style='color: darkread;' href='mailto:[email protected]'>[email protected]</a></h3><br>
                    <a href='https://plus.google.com/113626141520121345204/posts' style='color:blue;'>Follow Me On google Plus</a><br>
                    <a href='http://twitter.com/thorbis' style='color:blue;'>Follow Me On Twitter</a><br>
                    <a href='http://www.linkedin.com/profile/view?id=226237754&goback=%2Enmp_*1_*1_*1_*1_*1_*1_*1_*1_*1_*1&trk=spm_pic' style='color:blue;'>Find Me on Linked In</a><br>
                    <a href='http://facebook.com/thorbisinc' style=' color:blue;'>Follow Me On Facebook</a><br>
                    <a href='http://www.youtube.com/user/byronwade10' style=' color:blue;'>Subscrib To Me On YouTube</a><br>
                    <a href='https://github.com/Thorbis/Rejoice' style=' color:blue;'>Fork Me On GitHub</a></br><hr>" . "Name: " . $firstname . "<br>" . "Last: " . $lastname . "<br>" . "Email: " . $email . "<br>" . "cell: " . $cell . "<br>" . "Website: <a href='" . $website . "'>CLIENT WEBSITE<a/><br>";
                                $headers = "From: $from\r\n";
                                $headers .= "Content-type: text/html\r\n";
                                if (mail($to, $subject, $message, $headers)) {
                                                echo ("<p>Since You Have Used My services I will get an email stating that you have filled out this form and i will contact you back within 6 hours of you submiting the form! Also you sill get an adutomated message of exactly what i get!</p>");
                                } //mail($to, $subject, $message, $headers)
                                else {
                                                echo ("<p>I dident get a message stating that you have filled out the form can you manualy send me your email and info so i can customize your website please my email is [email protected] thank you :D</p>");
                                }
                                // Insert data into mysql
                                $sql    = "INSERT INTO $tbl_name(firstname, lastname, email, website, cell, overview)VALUES('$firstname', '$lastname', '$email', '$website', '$cell', '$overview')";
                                $result = mysql_query($sql);
                                // if successfully insert data into database, displays message "Successful".
                                if ($result) {
                                                echo "Successful";
                                                echo "<BR>";
                                                echo "This is your new resume site i will edit it with your info ASAP once i have contected you: <a href='" . $website . "'>Your Website</a>";
                                                echo "<BR>";
                                                echo "<a href='http://www.thorbis.com'>Back to Home Page</a>";
                                } //$result
                }
}
?>