milescook
-
Posts
1 -
Joined
-
Last visited
Never
We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.
Upload file problem
in PHP Coding Help
Posted
Code is as follows for do_upload
[code]<?php
$err_upload = "";
$image_file = $_FILES[’upload_file’];
$temporary_name = $image_file[’tmp_name’];
if (is_uploaded_file($temporary_name)) {
// get image information
$image_metadata = getimagesize($temporary_name);
if ($image_metadata) {
$image_width = $image_metadata[0];
$image_height = $image_metadata[1];
$image_type = $image_metadata[2];
$save_name = $temporary_name;
switch ($image_type)
{
case IMAGETYPE_GIF:
$save_name .= ".gif";
break;
case IMAGETYPE_PNG:
$save_name .= ".png";
break;
default:
$err_upload = "Sorry… we only allow gif and png images.";
break;
}
if (! $err_upload) {
if (move_uploaded_file($tmp_name, "uploads/file")) {
// you might update a database with key information here so
// that the image can be used later
} else {
$err_upload = "Sorry… something went horribly awry.";
}
}
}
} else {
// some error occurred: handle it
switch ($image_file[’error’])
{
case 1: // file too big (based on php.ini)
case 2: // file too big (based on MAX_FILE_SIZE)
$err_upload = "Sorry… image too big.";
break;
case 3: // file only partially uploaded
case 4: // no file was uploaded
case 6: // missing a temporary folder
case 7: // failed to write to disk (only in PHP 5.1+)
$err_upload = "Sorry… failed to upload… problem with server.";
break;
}
}
if ($err_upload) {
print $err_upload;
} else {
print "Success!!!";
}
?> [/code]
I have carried out the recommendations, and I have turned on error reporting. I get this:
[code]Notice: Use of undefined constant �upload_file� - assumed '�upload_file�' in /usr/local/apache2/html/do_upload.php on line 5
Notice: Undefined index: �upload_file� in /usr/local/apache2/html/do_upload.php on line 5
Notice: Use of undefined constant �tmp_name� - assumed '�tmp_name�' in /usr/local/apache2/html/do_upload.php on line 6
Notice: Use of undefined constant �error� - assumed '�error�' in /usr/local/apache2/html/do_upload.php on line 46
Success!!![/code]
My phpinfo is at http://apollo.cookieonline.net/phpinfo.php
Page is at http://apollo.cookieonline.net/upload_file.html
It says success, but the file is not in uploads!!
Please help!