Page 1 of 1

Question..

Posted: Tue Oct 28, 2003 9:06 am
by nick2
Am I allowed to ask another question or am I going to get accused?

I've been trying all yesterday to get my code to work.. but it just makes no errors and simply just doesn't upload anything..

Code: Select all

<?php

$path = "";
$max_size = 200000;

if (!isset($HTTP_POST_FILES['userfile'])) exit;

if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {

if ($HTTP_POST_FILES['userfile']['size']>$max_size) { echo "The file is too big<br>\n"; exit; }
if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg")) {

if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "The file already exists<br>\n"; exit; }

$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .
$HTTP_POST_FILES['userfile']['name']);
if (!$res) { echo "upload failed!<br>\n"; exit; } else { echo "upload sucessful<br>\n"; }

echo "File Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n";
echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n";
echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n";
} else { 
echo "Wrong file type<br>\n"; exit; }

}

?>
I've been trying different things.. looking at the php manual and it all looks right yet nothing works.. if one of you would be kind enough to maybe explain whats going on? :P

could it be a setting server side that blocks it?

Posted: Tue Oct 28, 2003 9:38 am
by twigletmac
Quick question, just so I know before I try to help - which version of PHP are you using?

Mac

Posted: Tue Oct 28, 2003 9:41 am
by nick2
PHP Version 4.3.2

Posted: Tue Oct 28, 2003 9:52 am
by twigletmac
Few questions for you:
  • What does the form look like through which you try to upload the file?
  • What do you get if you put:

    Code: Select all

    echo '<pre>';
    print_r($_FILES);
    echo '</pre>';
    at the top of the form processing page?
  • What is the output of:

    Code: Select all

    echo '<pre>';
    echo 'PHP Version: '.phpversion()."\n";
    echo 'Display Errors: '.ini_get('display_errors')."\n";
    echo 'Error Level: '.(ini_get('error_reporting') == '2047' ? 'E_ALL' : 'Not E_ALL')."\n";
    echo 'Register Globals: '.(ini_get('register_globals') == '' ? 'Off' : 'On')."\n";
    echo '</pre>';
Mac

Posted: Tue Oct 28, 2003 9:58 am
by nick2
Upload process:

Code: Select all

Array
(
)

Output of the other stuff:

Code: Select all

PHP Version: 4.3.2
Display Errors: 1
Error Level: Not E_ALL
Register Globals: On

Posted: Tue Oct 28, 2003 10:01 am
by twigletmac
And the initial form?

Mac

Posted: Tue Oct 28, 2003 10:03 am
by nick2
Oh sorry forgot:

Code: Select all

<center><form method="POST" action="upload.php">
  <p><input type="file" name="userfile" size="20">
<input type="submit" value="Do It!" name="B1">
  - <font size="2">Upload an image</font></p>
</form></center>

also since your here..is there a simple way to pop up a window without using javascript.. maybe using php?

Posted: Tue Oct 28, 2003 10:07 am
by twigletmac
Before I have a look at the form - popups are a clientside thingie, therefore you need JavaScript.

Mac

Posted: Tue Oct 28, 2003 10:07 am
by nick2
ok.. :(

javascript just seems very confusing so I tend to avoid it. :oops:

Posted: Tue Oct 28, 2003 10:09 am
by twigletmac
Try changing:

Code: Select all

<form method="POST" action="upload.php">
to

Code: Select all

<form enctype="multipart/form-data" action="upload.php" method="POST">
and definitely have a read of:
http://php.net/manual/en/features.file-upload.php
Mac

Posted: Tue Oct 28, 2003 10:20 am
by nick2
Thanks its worked ^__^

but.

^-- gotta hate the buts..

Code: Select all

<?php
include 'includes.php';
###
$path = $_COOKIE[user] . "/";
$max_size = 200000;

if (!isset($HTTP_POST_FILES['userfile'])) exit;

if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {

if ($HTTP_POST_FILES['userfile']['size']>$max_size) { echo "The file is too big<br>\n"; exit; }
if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg")) {

if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "The file already exists<br>\n"; exit; }

$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .
$HTTP_POST_FILES['userfile']['name']);
if (!$res) { echo "upload failed!<br>\n"; exit; } else { 
header("location: Http://www.slices.net/pictures.php");
}
?>

KEEPS on giving me parse errors I keep changing everything around and it should work by looks of it yet it doesn't it gives me errors on the header around there...:(

Posted: Tue Oct 28, 2003 5:54 pm
by qads
post the error messages.

Posted: Tue Oct 28, 2003 6:38 pm
by volka
must be a PHP Parse error: parse error, unexpected $end in blablabla
If you take more care about indenting your code you will find that there are closing curly brackets missing.

Posted: Tue Oct 28, 2003 6:54 pm
by JAM
A tip. Try to use { } and indents (preferably 4 spaces) like i rewrote it.
Its easier to spot issues with missing brackets.

(Note: Not entirely sure this works, but it looks okay from m position)

Code: Select all

<?php
    include 'includes.php';
    ###
    $path = $_COOKIE[user] . "/";
    $max_size = 200000;

    if (!isset($HTTP_POST_FILES['userfile'])) { 
        exit;
    }

    if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {

        if ($HTTP_POST_FILES['userfile']['size']>$max_size) { 
            echo "The file is too big<br>\n"; 
            exit; 
        }

        if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg")) {

            if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { 
                echo "The file already exists<br>\n"; 
                exit; 
            }

            $res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path . $HTTP_POST_FILES['userfile']['name']);

            if (!$res) { 
                echo "upload failed!<br>\n"; 
                exit; 
            } else {
                header("location: Http://www.slices.net/pictures.php");
            }

        } // missing

    } // missing
?>