Mysql
 sql >> डेटाबेस >  >> RDS >> Mysql

PHP का उपयोग कर सर्वर पर छवि अपलोड करते समय अन्य जानकारी के साथ डेटाबेस में फ़ाइल नाम कैसे स्टोर करें?

यहां उत्तर है आप में से उन लोगों के लिए जैसे मैंने पूरे वेब पर यह पता लगाने की कोशिश की कि यह कार्य कैसे करना है। एक सर्वर पर एक फोटो अपलोड करना जिसका फ़ाइल नाम एक mysql डेटाबेस में संग्रहीत है और अन्य प्रपत्र डेटा जो आप अपने डेटाबेस में चाहते हैं। कृपया मुझे बताएं कि क्या इससे मदद मिली।

सबसे पहले आपको जिस फॉर्म की आवश्यकता है:

    <form method="post" action="addMember.php" enctype="multipart/form-data">
    <p>
              Please Enter the Band Members Name.
            </p>
            <p>
              Band Member or Affiliates Name:
            </p>
            <input type="text" name="nameMember"/>
            <p>
              Please Enter the Band Members Position. Example:Drums.
            </p>
            <p>
              Band Position:
            </p>
            <input type="text" name="bandMember"/>
            <p>
              Please Upload a Photo of the Member in gif or jpeg format. The file name should be named after the Members name. If the same file name is uploaded twice it will be overwritten! Maxium size of File is 35kb.
            </p>
            <p>
              Photo:
            </p>
            <input type="hidden" name="size" value="350000">
            <input type="file" name="photo"> 
            <p>
              Please Enter any other information about the band member here.
            </p>
            <p>
              Other Member Information:
            </p>
<textarea rows="10" cols="35" name="aboutMember">
</textarea>
            <p>
              Please Enter any other Bands the Member has been in.
            </p>
            <p>
              Other Bands:
            </p>
            <input type="text" name="otherBands" size=30 />
            <br/>
            <br/>
            <input TYPE="submit" name="upload" title="Add data to the Database" value="Add Member"/>
          </form>

फिर यह कोड आपके डेटा को फ़ॉर्म से संसाधित करता है:

   <?php

// This is the directory where images will be saved
$target = "your directory";
$target = $target . basename( $_FILES['photo']['name']);

// This gets all the other information from the form
$name=$_POST['nameMember'];
$bandMember=$_POST['bandMember'];
$pic=($_FILES['photo']['name']);
$about=$_POST['aboutMember'];
$bands=$_POST['otherBands'];


// Connects to your Database
mysqli_connect("yourhost", "username", "password") or die(mysqli_error()) ;
mysqli_select_db("dbName") or die(mysqli_error()) ;

// Writes the information to the database
mysqli_query("INSERT INTO tableName (nameMember,bandMember,photo,aboutMember,otherBands)
VALUES ('$name', '$bandMember', '$pic', '$about', '$bands')") ;

// Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{

// Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {

// Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?> 

www.about.com से संपादित कोड



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. MySQL क्वेरी स्ट्रिंग में शामिल हैं

  2. MySQLdb का उपयोग करके कर्सर को कब बंद करें

  3. ऑटो वेतन वृद्धि प्राथमिक गिनती में अंतराल छोड़ रहा है

  4. MyCLI - स्वत:पूर्णता और सिंटैक्स-हाइलाइटिंग के साथ एक MySQL/MariaDB क्लाइंट

  5. MySQL कनेक्शन (max_connections) कैसे बढ़ाएं?