View Full Version : Image Upload Help

04-19-2007, 05:59 AM
Hey there I currently have some code from another website that seems to be working great except one little thing. When I load it in a web browser it gives me this 'Notice: Undefined variable: PHP_SELF in' the location.

I tried kinda 'playing' with it with no luck ill post a full section of code below.


echo('Upload images:

<FORM ENCTYPE="multipart/form-data" ACTION="' . $PHP_SELF . '" METHOD="POST">

The file: <INPUT TYPE="file" NAME="userfile">

<INPUT TYPE="submit" VALUE="Upload">


$path = "uploaded";

$max_size = 20000;

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") || ($HTTP_POST_FILES['userfile']['type']=="image/png")) {

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 .


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; }


$my_file = $HTTP_POST_FILES['userfile']['name'];


Like I said the code seems to do just what it says it would and it uploads images even with the error. I just want it to go away.

- Kevin

04-19-2007, 09:13 AM
Which line gets the error?

Using @function() suppresses error reporting, so if the mail() function was giving you a weird error but still working you could use @mail().

It may also be something you could do differently, so let us know which line it is.