代码在localhost中工作正常但在服务器中没有

时间:2013-11-13 12:17:12

标签: php forms

我需要将表单提交给数据库,我的表单及其php代码,以便在localserver中正确地提交到数据库中,但是当我在提交后将其上传到主服务器中时显示空的php文件,没有错误消息,数据也没有进入数据库, 当我包含上传图像的PHP代码时,这个问题就出现了,其他细节在表单中成功提交.....

作为一个学习者,所有的建议都是可以理解的......提前致谢

     <?php
     error_reporting(E_ALL);
     $name = $_POST['name'];
     $date = $_POST['year']."-". $_POST['month']."-".$_POST['date'];
     $date = mysql_real_escape_string($date);
        if (isset($_POST['gender'])){
    $gender = $_POST['gender'];
           }
       if (isset($_POST['maritalstatus'])){
    $maritalstatus = $_POST['maritalstatus'];
               }
    $registerby =$_POST['registerby'];
    $livingplace =$_POST['livingplace'];
    $qualification =$_POST['quali'];
    $occupation =$_POST['occupation'];
    $income = $_POST['income'];
    $contactno =$_POST['mobno'];
    $caste =$_POST['caste'];
    $email =$_POST['email'];

     if(isset($_POST['submit']))
      {
   //Assign the paths needed to variables for use in the script 
  $filePathFull = "/public_html/www.****.com/icons/".$_FILES["imagefile"] ["name"]; 
       $filePathThumb = "/public_html/www.*****.com/icons/"; 

           //Assign the files TMP name and TYPE to variable for use in the script 
       $tmpName = $_FILES["imagefile"]["tmp_name"]; 
      $imageType = $_FILES["imagefile"]["type"]; 

//Use a switch statement to check the extension of the file type. If file type is not valid echo an error 
switch ($imageType) { 
    case $imageType == "image/gif": 
        move_uploaded_file($tmpName,$filePathFull); 
        break; 
    case $imageType == "image/jpeg": 
        move_uploaded_file($tmpName,$filePathFull);         
        break; 
    case $imageType == "image/pjpeg": 
        move_uploaded_file($tmpName,$filePathFull);         
        break;     
    case $imageType == "image/png": 
        move_uploaded_file($tmpName,$filePathFull);         
        break; 
    case $imageType == "image/x-png": 
        move_uploaded_file($tmpName,$filePathFull);         
        break;     
    default: 
        echo 'Wrong image type selected. Only JPG, PNG or GIF formats accepted!.'; 
} 

    // Get information about the image 
    list($srcWidth, $srcHeight, $type, $attr) = getimagesize($filePathFull); 

    $origRatio = $srcWidth/$srcHeight; 

    //Create the correct file type based on imagetype 
    switch($type) { 
    case IMAGETYPE_JPEG: 
            $startImage = imagecreatefromjpeg($filePathFull); 
            break; 
    case IMAGETYPE_PNG: 
            $startImage = imagecreatefrompng($filePathFull); 
            break; 
    case IMAGETYPE_GIF: 
            $startImage = imagecreatefromgif($filePathFull); 
            break; 
    default: 
            return false; 
    } 


//Get the image to create thumbnail from 
$startImage;  


$width = 150; 
$height = 150; 

if ($width/$height > $origRatio) { 
       $width = $height*$origRatio; 
}else{ 
       $height = $width/$origRatio; 
} 


 //Create the thumbnail with true colours 
 $thumbImage = imagecreatetruecolor($width, $height); 

//Generate the resized image image 
    imagecopyresampled($thumbImage, $startImage, 0,0,0,0,  $width, $height, $srcWidth, $srcHeight);     

//Generate a random number to append the filename. 
$ran = "thumb_".rand () ;     
$thumb2 = $ran.".jpg"; 


//global $thumb_Add_thumb; 

//Create the path to store the thumbnail in. 
$thumb_Add_thumb = $filePathThumb; 
$thumb_Add_thumb .= $thumb2;   

 //Create the new image and put it into the thumbnails folder. 
  imagejpeg($thumbImage, "" .$filePathThumb. "$thumb2");  
  }
   if(isset($_POST['submit']))
   {
$connection = mysql_connect("localhost","user", "pass"); 
    if(! $connection) { die('Connection Failed: ' . mysql_error()) ;}
      mysql_select_db("database") or die (error.mysql_error());
$sql = "INSERT INTO quickregister(Name,Gender,Dateofbirth,Maritalstatus,Qualification,Income,Livingplace,Caste,Contactno,Emailaddress,Registerby,picture,filePathThumb,Occupation)VALUES('".$name."','".$gender."','".$date."','".$maritalstatus."','".$qualification."','".$income."','".$livingplace."','".$caste."','".$contactno."','".$email."','".$registerby."','".$filePathFull."','".$thumb_Add_thumb."','".$occupation."')";
  $retval = mysql_query( $sql, $connection );
 if(! $retval )
 {
 die('Could not enter data' . mysql_error());
  }

 echo "<b>Your data was added to database</b>";
     }
   ?>

1 个答案:

答案 0 :(得分:1)

switch代码毫无意义。显然你错过了switch/caseif的关系,这是错误的:

switch ($imageType) { 
    case $imageType == "image/gif": 
        move_uploaded_file($tmpName,$filePathFull); 
        break;

    ... 

    default: 
        echo 'Wrong image type selected. Only JPG, PNG or GIF formats accepted!.'; 
} 

应该是:

switch ($imageType) { 
    case "image/gif": 
        move_uploaded_file($tmpName,$filePathFull); 
        break;