Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.


Results 1 to 5 of 5

Thread: [PHP] General question about if

  1. #1

    [PHP] General question about if

    PHP Code:

    if( copy($source$dest) )
    $msg "Copied $source to $dest";


    If you have this code, $source will be copied to $dest, because if the command works, then it will return "true." But how would you test if the file could be copied or not without actually executing the command? This would be useful if you have a user wanting to copy a file to another folder. It would check if it could be done. Then give the user a "are you sure?" prompt.

  2. #2

    Your script should be looking something like this...
    PHP Code:
    // Define $source
        // Define $dest
        // Display a dialog box asking 'are you sure' question
    if (YES is pressed from the dialog box)
    copy($source$dest) ) 
    $msg "Copied $source to $dest"
    CyanBlue / Jason Je / Flash Developer

  3. #3
    no that's no what he's after... He wants to know if it's possible to copy the file first, then the dialog box thing.
    But I don't really know if that's possible... u could like... copy and then delete it to see if it is possible but that is just pointless and waaaay slow... forget what I said
    I don't think that's possible

    Member #1 of the "Don't message me your flash questions" cult

  4. #4
    you could use a very small temp file for write testing if you really wanted to pre-test, but the standard pattern would be to confirm that they want to move it, then attempt to move it and throw an error if that fails.

    so I'd go with the latter, what CB suggests.

  5. #5

    i would kick it like that:
    PHP Code:

    relapath ("source");
    $destination realpath ("destination");

    if (@isset (
    $_GET['do_it'])) {
    copy ($source$destination) ? $output "file {$source} coppied" $output "file {$source} not copied";
    } else if (
    is_writable (dirname ($destination))) {
    $output "would you really like to copy {$source} to {$destination}?<br /><a href=\"?do_it=\">ok</a>";
    } else {
    $output "sorry dude, file can not be copied there...";

    print (

    should work
    and remeber it's only a conspect of how you can do it

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us


Copyright 1999 - 2012