使用PHP将多个图像上载到多个Mysql字段

时间:2014-08-13 06:28:13

标签: php mysql image upload

我有一个php表单,我必须通过浏览文件选项来保存单独的文件/图像以分离mysql列并通过按一个确认按钮保存/插入。我已经检查了很多教程,但找不到完成这项任务的确切内容。

表单视图在此处给出:http://demo.softbd.com/student/registration/form-step-02/

现在建议我如何在一次尝试mysql中保存这些单独的图片。我只会在mysql中保存图像路径并将图像移动到文件夹中。

非常感谢任何帮助

SqL& PHP代码

     <?php 
$valid_formats = array("jpg","jpeg","JPG", "png", "gif", "bmp");
$max_file_size = 1024*1024*1024;
$dir = "upload/";

// If File Submitted
if($_SERVER['REQUEST_METHOD'] == "POST"){
    $ext = pathinfo($_FILES['profile']['name'], PATHINFO_EXTENSION);
    if ( in_array($ext, $valid_formats)) {
        if( $_FILES['profile']['size'] < $max_file_size ){
            $uniq = base_convert(uniqid(), 16, 10);
            $tmp = $_FILES['profile']['tmp_name'];
            $uniq_file_name = $uniq.".".$ext;
            if(move_uploaded_file($tmp, $dir.$uniq_file_name)){

$query= "INSERT INTO `studentconsultancy`.`student_registration_form` (`ID`,`FirstName`, `LastName`,`DateOfBirth`, `Email`, `LandPhone`, `CellPhone`, `Address`, `Address2`, `City`, `State`, `ZipCode`, `Country`, `InterestLevel`, `InterestLevelOther`, `EnrollYear`, `EnrollSemester`, `InterestCountry`, `InterestCountryOther`, `EnglishProficiency`, `EnglishOther`, `Score`, `Grade`, `YearOfExamTaken`, `CountryOfExamTaken`, `LastAcademicQualification`, `CourseName`, `ResultGrade`, `InstituteName`, `PassportScanCopy`, `AcademicDocumentScanCopy1`, `AcademicDocumentScanCopy2`, `AcademicDocumentScanCopy3`, `AcademicDocumentScanCopy4`, `ProfilePicture`, `NationalIDScanCopy`, `DocList`, `EntryDate`) 

VALUES ('NULL','$firstname', '$lastname', '$date', '$email', '$landphone', '$cellphone', '$address', '$address2', '$city', '$state', '$zip', '$country', '$interestlevel', '$interestlevelother', '$enrollyear', '$enrollsemester', '$interestcountry', '$interestcountryother', '$englishprof', '$english_other', '$score', '$grade', '$yearofexam', '$countryofexam', '$lastacademicq', '$coursename', '$resultgrade','$institutename','$passport','$academic1','$academic2','$academic3','$academic4','$profile','$nid','$doclist',NOW())";

$msg = "Uploading successful!";
            }
            else{
                $msg = "Problem while moving file";
            }
        }
        else{
            $msg = "File is too large";
        }
    }
    else{
        $msg = "Worng file format";
    }
}

 if (!mysql_query($query,$link))
  {
  die('Error: Error in Registration,try later ' . mysql_error());
  }

此致 Ishtiaque

0 个答案:

没有答案
相关问题