how to save file along with some data in php

how to save html form data to text file using php
php write to file append
php create file in directory
how to save php file in html
php write array to file
php create file if not exists
php create empty file
file_put_contents not working

I have html input fields.

Those input fields are




Now I need to save name, title, lyrics and upload files into database at same time.How to do this??

Here I share my codes

 $connection = mysqli_connect("localhost", "root", "upload"); // 
     Establishing Connection with Server
   $db = mysqli_select_db($connection, "song"); // Selecting Database from 
  if(isset($_POST['submit'])){ // Fetching variables of the form which 
  travels in URL
  $name = $_POST['name'];
  $title = $_POST['title'];
  $lyrics = $_POST['lyrics'];

   if($name !=''||$title !=''||$lyrics !=''){
   //Insert Query of SQL
   $query = mysqli_query($connection, "insert into users(name, title, 
   lyrics) values ('$name', '$title', '$lyrics')");
   echo "<br/><br/><span>Data Inserted successfully...!!</span>";
   echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
   mysqli_close($connection); // Closing Connection with Server

   <div style="margin:1em auto; width:333px; text-align:center;">
    <form method="post" enctype="multipart/form-data">

   <table style="margin-top: 200px;line-height: 27px;">
     <tr><td><label for='name' >Name: </label></td>
         <td> <input type="text" name="name"></td></tr>

        <tr><td>   <label for='title' >Title: </label></td>
       <td> <input type="text" name="title"></td></tr>

         <tr><td>  <label for='lyrics' >lyrics: </label></td>
        <td><textarea cols="25" name="lyrics" rows="5"></textarea></td></tr>

         <tr> <td>  <label for='file'>upload:</label></td>
         <td><input type="file" name="files" multiple="multiple"></td>
        <td><input type="submit" name="upload" value="upload!" ></td></tr>
              <button class="submit" name="submit" type="submit" 

I will save name, title, lyrics data into database.

But when I try to save upload file into database, it shows an error

Use this

$info = pathinfo($_FILES['userFile']['name']);
$ext = $info['extension']; // get the extension of the file
$newname = "newname.".$ext; 

$target = 'images/'.$newname;
move_uploaded_file( $_FILES['userFile']['tmp_name'], $target);

Include() and Require() Function in PHP, How do I save Web form data to a text file? I have a simple html form along with some php codes in a index.php file, and my question is: how can I save that form data and use them in a diffrent page? Php code looks like this:

You cannot receive file content is a $_POSTentry. Files are uploaded in a temporary directory, and you'll have deal wth $_FILES array. Check POST method uploads documentation page for more.

how to save file along with some data in php, Use this $info = pathinfo($_FILES['userFile']['name']); $ext = $info['extension']; // get the extension of the file $newname = "newname.".$ext  PHP Create File - fopen() The fopen() function is also used to create a file. Maybe a little confusing, but in PHP, a file is created using the same function used to open files. If you use fopen() on a file that does not exist, it will create it, given that the file is opened for writing (w) or appending (a).

To access uploaded files you need to refer to $_FILES.

$file = $_FILES['files'];
$base64 = base64_encode(file_get_contents($file['tmp_name']));

And then you can save $base64 to a database as you save other fields that come in form. But I strongly discourage you from saving files in a database. Instead, you should consider saving a file in a chosen directory and save only name of the file in the database.

PHP File Create/Write, PHP Overwriting. Now that "newfile.txt" contains some data we can show what happens when we open an existing file for writing. All the existing data  Demonstrates using PHP to save data to a textfile on a server and read in and display text from a textfile on a server. Also demonstrates basic data clean up, using functions, and file includes.

Save HTML Form Data in a (.txt) Text File in PHP, Step by step guide on How to put the HTML form field data in a text file or dot txt file in PHP. Create a PHP file and put the below code and save it. <! create a new file in the same directory or folder & name it data. txt and save it. Now run the PHP file. enter any text and hit on submit button and check your data. We call request.send() to send the request to the server, which sends all the data we want to save in todo.json along with the request. When we send the request, the save.php script is called on the server, which saves the to-do data into the file todo.json .

Uploading files with PHP (POST method), Introduction; File Upload Form; Handling uploaded files with PHP; Saving the file At times you, or your users will want to upload some files onto your web server. files are saved in to a directory on the server, or as binary data in a database  I just intend to bring my little contribution to the use of DOMDocument::save() function along with PHP serialize() function. Sometimes you could have to serialize a PHP object before you put it into a XML structure (or other..). And then I suppose you could have to save this XML structure in a file.

Saving Uploaded Files in PHP - Image Uploader 7.0, This topic describes how to save files received from Image Uploader in PHP. data sent by clients, save it all to file system on a server or handle in some other way. All the metadata uploaded along with a file is accessible through the  Media Files Saved as PHP. Some browser plugins that download media from web pages will incorrectly capture the media file's correct extension. The file will save with the correct name, but with a PHP extension. This glitch occurs only occasionally and stems from the media file sourcing from a PHP-enabled page.

  • You aren't inserting any image into the database in your code?
  • what does the error say? your query is trying to insert data which seems to describe a SONG into USERS table. is that your intention?
  • What have you tried to remove the error on your own?
  • I need to upload songs with song name,title,lyrics at same time.
  • I dont know how to save files into database along with name,title,lyrics at same time