View Single Post
Old 02-08-2007, 10:21 AM   #25 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
PHP Photo Gallery

SDE,

Oh, sorry is that new code? i though it was the same as what i have already got.
Yes, is works fine, brilliant, only now i am greeted with another error, this time as follows:

Parse error: parse error, unexpected T_STRING in C:\Documents and Settings\Dale Piper\Desktop\xampplite\htdocs\Upload.php on line 61

Code:
  <?php
$errors = array();

// error checking
if (empty($_FILES['file'])) {
    $errors[] = 'no file uploaded';
}
if (!is_uploaded_file($_FILES['file']['tmp_name'])) {
    $errors[] = 'Possible file upload attack';
}

switch ($_FILES['file']['error'])
{
    case UPLOAD_ERR_INI_SIZE:
        $errors[] = 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; 

    case UPLOAD_ERR_FORM_SIZE:
        $errors[] = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.';

    case UPLOAD_ERR_PARTIAL:
        $errors[] = 'The uploaded file was only partially uploaded.';

    case UPLOAD_ERR_NO_FILE:
        $errors[] = 'No file was uploaded.';

    case UPLOAD_ERR_NO_TMP_DIR:
        $errors[] = 'Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.';
 
    case UPLOAD_ERR_CANT_WRITE:
        $errors[] = 'Failed to write file to disk. Introduced in PHP 5.1.0.';

    case UPLOAD_ERR_EXTENSION:
        $errors[] = 'File upload stopped by extension. Introduced in PHP 5.2.0.';
}

// your error checking
if ($_FILES["file"]["type"] != "image/gif" || $_FILES["file"]["type"] != "image/jpeg") {
    $errors[] = 'Wrong image format.';
}

if ($_FILES["file"]["size"] > 20000) {
    $errors[] = 'File is too large.';
}

if ($count($errors)==0) {
    
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"])) {
        
      echo $_FILES["file"]["name"] . " already exists. ";
      
    } else {
        
      // add record to database  
      $result = mysql_query("insert into images (filename, caption) values('".$_FILES["file"]["name"]."','".mysql_real_escape_string($_POST['caption']."')")

      move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
    }
    
} else {

  echo "<b>Errors</b><br />";
  
  foreach ($errors as $each) {
      echo $each."<br />";
  }
}
?>
Many Thanks,
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote