Billed upload system

Her kan du få hjælp og stille spørgsmål til PHP!
Besvar
Mathias
Nørd
Nørd
Indlæg:145
Tilmeldt:5. apr 2012, 18:21
Kontakt:
Billed upload system

Indlæg af Mathias » 9. aug 2012, 18:02

Hejsa jeg er nu kommet så langt på min side at jeg gerne ville have billed upload system men det her fungere ikke rigtigt (Ved ikke om man skal have Mysql med)

Formular :

Kode: Vælg alt

<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="uploadImage" id="uploadImage">  
     <p>  
  	<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo MAX_FILE_SIZE; ?>" tyle="color: Red; background: White; border-style: solid; border-color: White; border-width: thin;" />  
         <label for="image">Upload image:"</label>  
         <input type="file" name="image" id="image" style="color: Red; background: White; border-style: solid; border-color: White; border-width: thin;" />   
     </p>  
     <p>  
       <label for="caption">Caption:</label>  
       <input type="text" name="caption" id="caption" tyle="color: Red; background: White; border-style: solid; border-color: White; border-width: thin;" />  
     </p>  
     <p>  
         <input type="submit" name="upload" id="upload" value="Upload" style="background-color: Black; border-color: white; color: White;" />  
     </p>  
     <input type="hidden" name="MM_insert" value="uploadImage" tyle="color: Red; background: White; border-style: solid; border-color: White; border-width: thin;" />  
</form>  
Og der hvor den uploader :

Kode: Vælg alt

<?php   
$target = "images/"; $target = $target . basename( $_FILES['photo']['name']);   
?>  
   
<?php define ('MAX_FILE_SIZE', 10240 * 500); ?>  
<?php require_once('../Connections/employees.php'); ?>  
<?php  
if (!function_exists("GetSQLValueString")) {  
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")   
{  
   if (PHP_VERSION < 6) {  
     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;  
   }  
   
   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);  
   
   switch ($theType) {  
     case "text":  
       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";  
       break;      
     case "long":  
     case "int":  
       $theValue = ($theValue != "") ? intval($theValue) : "NULL";  
       break;  
     case "double":  
       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";  
       break;  
     case "date":  
       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";  
       break;  
     case "defined":  
       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;  
       break;  
   }  
   return $theValue;  
}  
}  
   
$editFormAction = $_SERVER['PHP_SELF'];  
if (isset($_SERVER['QUERY_STRING'])) {  
   $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);  
}  
   
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "uploadImage")) {  
     
   // make sure it's a genuine file upload  
   if (is_uploaded_file($_FILES['image']['tmp_name'])) {  
     
 
  $filename = str_replace(' ', '_', $_FILES['image']['name']);  
  // get the MIME type  
  $mimetype = $_FILES['image']['type'];  
  if ($mimetype == 'image/pjpeg') {  
  	$mimetype= 'image/jpeg';  
  }  

  $permitted = array('image/gif', 'image/jpeg', 'image/png');  
    
   
  if (in_array($mimetype, $permitted)   
  	&& $_FILES['image']['size'] > 0   
  	&& $_FILES['image']['size'] <= MAX_FILE_SIZE) {  
    switch ($_FILES['image']['error']) {  
  	case 0:  
     // get the file contents  
     $image = file_get_contents($_FILES['image']['tmp_name']);  
     // get the width and height  
     $size = getimagesize($_FILES['image']['tmp_name']);  
     $width = $size[0];  
     $height = $size[1];  
   
     
   $insertSQL = sprintf("INSERT INTO images (filename, mimetype, caption, image, width, height) VALUES (%s, %s, %s, %s, %s, %s)",  
                        GetSQLValueString($filename, "text"),  
                        GetSQLValueString($mimetype, "text"),  
                        GetSQLValueString($_POST['caption'], "text"),  
                        GetSQLValueString($image, "text"),  
                        GetSQLValueString($width, "int"),  
                        GetSQLValueString($height, "int"));  
   
   

  include 'employees.php';   
   
   
       
       
     if ($Result1) {  
    $result = "$filename uploaded successfully.";  
     } else {  
    $result = "Error uploading $filename. Please try again.";  
     }  
     break;  
  	case 3:  
  	case 6:  
  	case 7:  
  	case 8:  
     $result = "Error uploading $filename. Please try again.";  
     break;  
  	case 4:  
     $result = "You didn't select a file to be uploaded.";  
    }  
  } else {  
    $result = "$filename is either too big or not an image.";  
  }  
   }  
}  
?>  

Brugeravatar
ThomasI
Grundlægger
Grundlægger
Indlæg:1528
Tilmeldt:28. dec 2010, 10:49

Re: Billed upload system

Indlæg af ThomasI » 10. aug 2012, 09:33

Ligner et script som du har fundet på nettet - har du husket at tilpasse det 100% til det du sidder og laver...

Har du f.eks en fil liggende der hedder employees.php ?

Har du nogen ide om hvor det går galt... hvad er fejlkoden og hvad udskriver scriptet nu når det ikke virker?

Mathias
Nørd
Nørd
Indlæg:145
Tilmeldt:5. apr 2012, 18:21
Kontakt:

Re: Billed upload system

Indlæg af Mathias » 10. aug 2012, 14:47

Hej Thomas jeg har faktisk aldrig prøvet med Billed system før men jeg har ændret det med employees.php har jeg skifte ud med billeder.php og den siger ikke noget som helst Men jeg ville sige jeg har prøvet med jeres Billed system som slet ikke virket.

shukbob
Rutineret
Rutineret
Indlæg:60
Tilmeldt:1. mar 2012, 06:37

Re: Billed upload system

Indlæg af shukbob » 17. aug 2012, 19:16

Prøv at se denne her: http://www.w3schools.com/php/php_file_upload.asp
Måske hjælper det.

Besvar