Jump to content

mkosmosports

Members
  • Posts

    196
  • Joined

  • Last visited

    Never

Posts posted by mkosmosports

  1. Hello,

     

    I have a 'page' parameter in the URL. I dont know whether it will be preceeded by a ? or a &, but I want to take it out and put the result into a variable.

     

    Right now Im accomplishing that using simple regex and if/else statements. Im wondering if there is a ready-made php function which would know how to manipulate URL's like that.

     

    Thanks.

    mkosmosports

  2. Hey,

     

    Is there any way to show the number sign of any number (ie. if its positive, show the + before it, if its zero, show nothing and if its negative show -) aside from the obvious if/else condition? Perhaps a built-in function...

     

    Thanks in advance.

    mkosmosports

  3. Thanks for your input everyone.

     

    I agree with your example revraz, but what about cases where your not manipulating the values, or the values are not user-inputted, like when using the $_SERVER or $_SESSION superglobals (I shouldnt of used the $_POST example in my intial post)?

     

    In those cases, does it really just boil down to preference and coding styles? (rab, it looks like you agree with that)

     

    I did read that as well regarding the $_POST superglobal dsaba. (it replaces all dots with underscores)

     

    Thanks again.

     

     

  4. Hello,

     

    Im wondering about the usage of superglobals. Ive noticed a lot of tutorials tend to always put the superglobals variable into another variable. Ex. $testvar = $_POST['testvar'];

     

    If youre not planning to manipulate its value, wouldnt it make more sense (and potentially faster because you dont need to define another variable) to always just refer to $_POST['testvar']?

     

    Or are there some possible issues in doing this?

     

    Im hoping someone could clear this up for me.

     

    Thanks!

    mkosmosports

     

  5. Hey,

     

    Ive got the following md array

     

    Array
    (
        [0] => Array
            (
                [id] => 3
                [title] => Title
                [date] => Oct 29 08:11
            )
    
        [1] => Array
            (
                [id] => 5
                [title] => Title
                [date] => Oct 29 08:25
            )
    
        [2] => Array
            (
                [id] => 6
                [title] => Title
                [date] => Oct 29 08:18
            )
    
        [3] => Array
            (
                [id] => 4
                [title] => Title
                [date] => Oct 29 08:16
            )

     

    What I want to do is sort the 1st level array by the date in the second level array (with the keys getting reordered accordingly) so this one would read as follows after:

     

     

    Array
    (
        [0] => Array
            (
                [id] => 6
                [title] => Title
                [date] => Oct 29 08:18
            )
    
        [1] => Array
            (
                [id] => 5
                [title] => Title
                [date] => Oct 29 08:17
            )
    
        [2] => Array
            (
    
                [id] => 4
                [title] => Title
                [date] => Oct 29 08:16
            )
    
        [3] => Array
            (
                [id] => 3
                [title] => Title
                [date] => Oct 29 08:11
            )

     

    Any ideas?

     

    Thanks!

  6. Hey,

     

    I want to issue multiple queries in my script using PDO. All of of these queries will either retrieve one row with multiple columns or one row with one column, so I am using either fetch or fetchColumn to get the data.

     

    Now, I ran into an error message telling me: "General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll()."

     

    If there is only one row being retrieved (and I know this for sure), how is it that unbuffered queries are still active?

     

    And whats the most effective way to get around this? I can use fetchAll or loop with fetchColumn or call PDOStatement->closeCursor(); after each query data retrieval statement.

     

    Anyone else encounter this? Any advice?

     

    Thanks.

  7. *bump bump* :)

     

    I hate to be annoying but Im still struggling with this. Quick recap, I want to allow users to upload images from other web locations to my server. However, they have to be valid gif,jpg or png images and cannot excede 20000 bytes.

     

    I've come up with the following test script:

     

    $deal_image = trim($_POST['deal_image']);
    $deal_image_ext = substr($deal_image,-4);
    
    $goodimgtypes = array(".gif",".jpg",".png");
    if(!in_array($deal_image_ext,$goodimgtypes)) {	//only check image url's ending with .png, .gif or .jpg
    echo 'bad extension';	//invalid image type in url filename
    exit();
    }	
    if (!@get_headers($deal_image,1)) {	//only check image url's from which we get http header responses
    echo 'unable to get headers back, not a valid url';	//unable to get header response back, file is not accessible through http	
    exit();
    }
    $headerarr = get_headers($deal_image, 1);
    $filesize = $headerarr['Content-Length'];
    $filetype = $headerarr['Content-Type'];
    $goodimgtypes = array("image/gif","image/jpg","image/png");
    if(!in_array($filetype,$goodimgtypes) || $filesize > 20000) {	//only jpg,gif,png and smaller than 20000 bytes
    echo 'bad filetype or image too big';	//not a valid image type or too big
    exit();
    }
    $getfile = file_get_contents($deal_image,FALSE,NULL,0,20000);	//get 20000 bytes of the image in case fake headers were sent back

     

    What I want to do though is make sure the $getfile is indeed a valid/complete image before I put I on my server. Is there a way to do it having the image data inside the $getfile string?

     

    Or is this approach just not gonna work?

     

    Any advice/input much appreciated!

    Thanks.

  8. Hey,

     

    Im marking this topic unsolved again as I wanted to know if using get_headers to obtain remote file information is really a safe method?

     

    What Im doing is basically allowing users to upload an image from a remote web location which has to be jpeg,gif or png and not larger than 20000 bytes.

     

    Now, cant the user uploading the file just choose a file which they know will send fake headers back, so for example a file is 2GB and its mpeg, but it sends back headers saying its only 15000 and its a jpg type file?

     

    I heard you can conceal php inside valid imagery even. Am I worried for nothing? If Im not, Is there a way to determined if a remote file is TRULY an image (jpg,png,gif) and is under 20000 bytes?

     

    Thanks all!

  9. Thanks rajivgonsalves,

     

    I do plan on downloading the image that way, but Im still having trouble validating the image, I dont want it to be be bigger than 20KB and it has to be either a jpg, gif or png file.

     

    Im trying exif_imagetype, but it doesnt want to accept urls.

     

    Anyone know of a way to validate images residing on other web locations before downloading them?

     

    Thanks.

  10. Those tutorials would apply to that as well Man on Scooter.

     

    If you can get a handle on retrieving from the mysql db, then you can put the returned values inside the matching value attribute of your input or in between the textarea tags of your form to fill them.

  11. Hey,

     

    I want to allow users of my site to be able to upload images from other web locations, to my server.

     

    Ive never done this before, but Im assuming I cant use the FILES array here and I should pass the file url through POST or GET, then validate it, then save it to the server using fwrite?

     

    Is that a correct approach? Can someone give me some advice or point to me to any good tutorials on doing this?

     

    Thanks.

  12. Thanks Barand. I have figured out whats wrong, but I made the mistake of assuming multidimensional sub-arrays dont implode....  ??? Sorry.

     

    Somewhere in my script I assigned a string to $mainarr['br']['sumconditions'] as opposed to assigning the string to $mainarr['br']['sumconditions'][], so I was in effect no longer imploding an array.

×
×
  • 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.