The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 5 of 5

Thread: [PHP] General question about if

  1. #1

    [PHP] General question about if

    PHP Code:
    <?php 

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

    ?> 

    echo($msg);
    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
    Howdy...

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

  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:
    <?php

    $source 
    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 (
    $output);

    ?>
    should work
    and remeber it's only a conspect of how you can do it
    Last edited by fluid_tw0; March 5th, 2005 at 06:58 PM.

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

 Credits

Copyright 1999 - 2012