Re: dont print echo

From: Date: Fri, 29 Feb 2008 20:30:41 +0000
Subject: Re: dont print echo
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-270766@lists.php.net to get a copy of this message
Daniel Brown wrote:
On Thu, Feb 28, 2008 at 11:08 PM, Emiliano Boragina <emiliano.boragina@gmail.com> wrote:
When I try the php the echo "no picture =("; is there. How can I do to don't appears the message before I upload de picture.
    Here's your code, re-written.
<? if(isset($_FILES)) {
    // The following regexp handles file extension checking.  Modify
it as needed.
    if(preg_match('/(.*)(bmp|gif|jpeg|jpg|png)$/i',substr(basename(__FILE__),-3,3)))
{
        $folder = 'pictures';
First, the op should use is_uploaded_file() to check and make sure that it is a file that was infact uploaded. http://us3.php.net/manual/en/function.is-uploaded-file.php Secondly, the op should use move_uploaded_file() instead instead of copy. http://us3.php.net/manual/en/function.move-uploaded-file.php They were created for a reason
        if(copy($_FILES['file']['tmp_name'] , $folder . '/' .
$_FILES['file']['name']))
            echo "Picture upload!";
        } else {
            echo "no picture =(";
        }
    } else {
        // Handle your "incorrect file type" errors here.
        die("Incorrect file type.");
    }
} ?> <form action="<?=$_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data"> <!--
    These fields are hidden.  You can only have one submit button per form,
    and we're only dealing with the image uploads with this question.
At least in "HTML 4 Specification" you can have more then one submit button. http://www.w3.org/TR/html4/interact/forms.html#submit-button
<input type="text" name="folder"> <input type="submit" value="ADD FOLDER"> <hr> --> <input type="file" name="file"> <input type="submit" value="UPLOAD"> </form>
-- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare

« previous php.general (#270766) next »