Jump to content

AyKay47

Members
  • Posts

    3,281
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by AyKay47

  1. Still have no idea what you mean. What "page" a user points to in order to perform the validation has no bearing on the actual validation - or the topic being discussed. And his query seemed perfectly self explanatory to me.

     

    Okay let me start from the beginning since you are not understanding basic language. In the original post, all the OP states is that he/she is validating a form by posting it to itself. Sticky input values alone are not validation. I would like the OP to post the code he is using to validate the form so I may check it, since his post was extremely brief and misled me as to how he is actually validating the form.

  2. He didn't mean that the act of posting a form to itself is validation. But, he is posting the form back to itself because that is where he put the validation logic. This is a common practice so that when validation fails you can easily redisplay the form and, like in this case, make the form values "sticky" so the user's previous input will populate the fields. This is so the user doesn't have to enter all of the data back into a form because one field was invalid.

     

    The reason I asked that question was to make sure that the OP is validating the user input correctly.

  3. hi all eventually created second directory on server called uploads2 and created new path? I guess which works. Code below. Happy enough, all I have to do is look in two different folders instead of one which isnt a biggie. Thanks loads for responses all, code below..

     

     

    $target_path = "uploads/";
    
    $target_path = $target_path . basename( $_FILES['selectedfile']['name']);
    
    if(move_uploaded_file($_FILES['selectedfile']['tmp_name'], $target_path)) {
    echo "The file ". basename( $_FILES['selectedfile']['name']).
    " has been uploaded";
    } else{
    echo "There was an error uploading the file, please try again!";
    }
    
    $target_path = "uploads2/";
    
    $target_path = $target_path . basename( $_FILES['selectedfile2']['name']);
    
    if(move_uploaded_file($_FILES['selectedfile2']['tmp_name'], $target_path)) {
    echo "The file ". basename( $_FILES['selectedfile2']['name']).
    " has been uploaded";
    } else{
    echo "There was an error uploading the file, please try again!";
    }

     

    Why do you need 2 directories? Store each file name in its own variable:

     

    $target_path = "uploads/";
    $fileName1 = $_FILES['selectedfile']['name'];
    $fileName2 = $_FILES['selectedfile2']['name'];
    
    $target_path1 = $target_path . $fileName1;
    $target_path2 = $target_path . $fileName2;
    
    
    if(move_uploaded_file($_FILES['selectedfile']['tmp_name'], $target_path1))
    {
     echo "The file ". $fileName1 . " has been uploaded";
    }
    else
    {
     echo "There was an error uploading the file, please try again!";
    }
    
    
    if(move_uploaded_file($_FILES['selectedfile2']['tmp_name'], $target_path2))
    {
     echo "The file ". $fileName2 ." has been uploaded";
    }
    else
    {
     echo "There was an error uploading the file, please try again!";
    }
    

  4. Because that is what you are telling it to name the file in this line:

     

    $target_path = $target_path . basename( $_FILES['selectedfile']['name']) .basename( $_FILES['selectedfile2']['name']);
    

     

    In both file uploads, you are saving to the same path, therefore overwriting the first file upload.

  5. I will try to simplify this for you. These lines are of significance:

     

    $str = "hEllo WoRld!";
    capitalize( $str );
    echo $str;
    

     

    The source of the parameter sent to the function "capitalize" is $str = "hEllo WoRld!";

    If the source $str was not passed to the function by reference, when you output $str it would remain "hEllo WoRld" since only a copy local to the function will be changed and not the source.

    However since you are passing the source to the function by reference, the source $str changes as well. In this particular case when you output $str you will get "HELLO WORLD".

  6. That's true, and we can add globals to the list as well. However, those are poor solutions. :) For a small project, I would store an array in a file like Andy-H does in his example. For bigger projects, I would store it in a database and cache it on the web server. For large projects, I would do neither and look into using a framework.

     

    Using global is never a valid solution.

  7. You really don't need to go to the bother of using a hidden checksum simply to prevent undefined index notices.

     

    No, you don't. However either method will work, bit of a habit for myself to use checksums since they have other advantages as well. What we can both agree on here is that relying on a submit button value may cause problems in some browsers.

  8. Here's a simple example for you (untested):

     

    $patterns = array('~((?:http|ftp)://(?:www)?\.[^.]+\.(?:com|org|gov))~i', '~(?<!http://)(www)\.([^.]+)\.(com|org|gov)~i');
    $replace = array('<a href="$1">$1</a>', '<a href="http://$1.$2.$3">http://$1.$2.$3</a>');
    $filtered_string = preg_replace($patterns, $replace, $text);
    

     

    The regex patterns will match 2 situations, the first will match URL's that begin with http:// or ftp:// and may possibly include www.

    The second will match URL's that begin with www and are not preceded by http://, it will then add http:// to the beginning of the URL to make it a valid external link.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.