Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: Skip if exist

  1. #1
    New Coder
    Join Date
    Jan 2012
    Location
    localhost
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Skip if exist

    Hello again.

    I have this:
    Code:
    file_put_contents("".$function['Title'].".png",file_get_contents("".$function['Poster'].""));
    What code do:
    copy image from website.com/a.png to a.png and website.com/b.png to a.png.

    After this I have:

    Code:
    echo "<img src=".$function['Title'].".png' />";
    Return:
    <img src="a.png" />
    <img src="b.png" />


    This is perfect, but I want to skip first code (file_put_contents) if images (a.png and b.png -> "".$function['Title'].".png") already exists. Hope u understand. Sorry for bad english.

    Thanks!
    Last edited by cat250; 01-15-2012 at 07:55 PM.

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    This post is just to clarify what I think you mean. You want to check if $function['title'].png is already in $function['roster'] before you use file_put_contents?
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #3
    New Coder
    Join Date
    Jan 2012
    Location
    localhost
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by BluePanther View Post
    This post is just to clarify what I think you mean. You want to check if $function['title'].png is already in $function['roster'] before you use file_put_contents?
    Hmm, yes, this is what I need.
    First to check if "".$function['Title'].".png" exist, if exist to execute echo "<img src=".$function['Title'].".png' />";, else execute file_put_contents and then echo... Thank u.

  • #4
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by cat250 View Post
    Hmm, yes, this is what I need.
    First to check if "".$function['Title'].".png" exist, if exist to execute echo "<img src=".$function['Title'].".png' />";, else execute file_put_contents and then echo... Thank u.
    To check if it exists in file_get_contents($function['radio'])?
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #5
    New Coder
    Join Date
    Jan 2012
    Location
    localhost
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by BluePanther View Post
    To check if it exists in file_get_contents($function['radio'])?
    What "radio"?
    Nop, to check if exists in folder. $function['Poster'] exists and it's picture, sure!

  • #6
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by cat250 View Post
    What "radio"?
    Nop, to check if exists in folder. $function['Poster'] exists and it's picture, sure!
    Sorry, I meant to say 'Poster' . So you want to check if it exists in file_get_contents($function['Poster'])?
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #7
    New Coder
    Join Date
    Jan 2012
    Location
    localhost
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by BluePanther View Post
    Sorry, I meant to say 'Poster' . So you want to check if it exists in file_get_contents($function['Poster'])?
    Nop, want to check if "".$function['Title'].".png" exists in folder.
    Last edited by cat250; 01-15-2012 at 05:21 PM.

  • #8
    12k
    12k is offline
    New Coder
    Join Date
    Jan 2012
    Posts
    29
    Thanks
    0
    Thanked 6 Times in 6 Posts
    use file_exists($filePath);

  • Users who have thanked 12k for this post:

    cat250 (01-15-2012)

  • #9
    New Coder
    Join Date
    Jan 2012
    Location
    localhost
    Posts
    14
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by 12k View Post
    use file_exists($filePath);
    Fixed, thank u.

    If u can, take a look here, please: http://www.codingforums.com/showthread.php?t=248918
    Thanks again!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •