473,405 Members | 2,141 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,405 developers and data experts.

Uploading files into a MySQL database using PHP

Atli
5,058 Expert 4TB
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t.

In situations where your PHP application needs to store entire files, the preferred method is to save the file onto the server’s file-system, and store the physical location of the file in your database. This is generally considered to be the easiest and fastest way to store files.

However, you may find yourself in situations where you would want to keep the file itself with the other data in your database. This gives you - or rather: MySQL - complete control over the file data, rather than just the location of the file on the server.

There are some downsides to this method though, such as; decreased performance and added complexity to both your PHP code and your database structure. This is something you should carefully consider before using this in a real-life application.

Having said that, this article demonstrates how you can upload a file from a browser into MySQL, and how to send the files back to the browser.

Before you start
To get through this smoothly, you should be familiar with the following:
The battle plan
As with all programs, before we start writing we need to plan a little ahead. Just so we know what we are going to write before we write it.

Before we start on the program, we need to design the database. This is not a complex design, as we are not talking about creating some complex filing system. We only need a single table, containing a BLOB field for our file and various other fields to store information on our file, such as name, size, type.

Now then. The first phase of the program is getting the file from our users onto the server where our PHP can interact with it. This is the simplest part of the process, requiring only a basic HTML form.

The second phase involves reading the uploaded file, making sure it was uploaded successfully and adding it to the database. This is a similar process as the one used when uploading a file to the file-system, but using the MySQL functions rather than the file-system functions.

The third phase is to list all files that have been uploaded and saved on the database, with a link so it can be downloaded. The only problem here would be the fact that the file does not exists on the server, so how do we create a link to it? That is a problem handled by phase 4, all we need to do in phase 3 is create a link with the ID of the file to be downloaded embedded in the URL.

The fourth, and final, part is the one that is most confusing about this process. The part where we fetch the file and send it to the client's browser.
We start by using the MySQL functions, and the ID sent by phase 3, to fetch the file data from the database. Then we set a few headers, letting the browser know what to expect, before finally sending the contents of the file.

Now, using this summary as a guide, lets start writing our program.

Phase 0: Building a database
The database is simple. One table with a BLOB field for the file data and a few fields for various pieces of information relating to the file:
Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE `file` (
  2.     `id`        Int Unsigned Not Null Auto_Increment,
  3.     `name`      VarChar(255) Not Null Default 'Untitled.txt',
  4.     `mime`      VarChar(50) Not Null Default 'text/plain',
  5.     `size`      BigInt Unsigned Not Null Default 0,
  6.     `data`      MediumBlob Not Null,
  7.     `created`   DateTime Not Null,
  8.     PRIMARY KEY (`id`)
  9. )
  10.  
As you see, we store the file name, including the extension.
We have the mime type, which we use to let the browser know what kind of file we are dealing with.
The size of the file in bytes.
And finally the data itself, in a MediumBlob field.

Phase 1: Uploading the file
Now, we need to get the file from the user. The table we designed does not require any additional information from the user, so we will make this simple and create a HTML form with only a single "file" input field and a submit button:
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html>
  2. <head>
  3.     <title>MySQL file upload example</title>
  4.     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  5. </head>
  6. <body>
  7.     <form action="add_file.php" method="post" enctype="multipart/form-data">
  8.         <input type="file" name="uploaded_file"><br>
  9.         <input type="submit" value="Upload file">
  10.     </form>
  11.     <p>
  12.         <a href="list_files.php">See all files</a>
  13.     </p>
  14. </body>
  15. </html>
Note the third attribute of the <form> element, "enctype". This tells the browser how to send the form data to the server. As it is, when sending files, this must be set to "multipart/form-data".
If it is set any other way, or not set at all, your file is probably not going to be transmitted correctly.

At the bottom, we have a link to the list we will create in phase 3.

Phase 2: Add the file to the database
In the form we built in phase 1, we set the action property to "add_file.php". This is the file we are going to build it this phase of the process.

This file needs to check if a file has been uploaded, make sure it was uploaded without errors, and add it to the database:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Check if a file has been uploaded
  3. if(isset($_FILES['uploaded_file'])) {
  4.     // Make sure the file was sent without errors
  5.     if($_FILES['uploaded_file']['error'] == 0) {
  6.         // Connect to the database
  7.         $dbLink = new mysqli('127.0.0.1', 'user', 'pwd', 'myTable');
  8.         if(mysqli_connect_errno()) {
  9.             die("MySQL connection failed: ". mysqli_connect_error());
  10.         }
  11.  
  12.         // Gather all required data
  13.         $name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']);
  14.         $mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']);
  15.         $data = $dbLink->real_escape_string(file_get_contents($_FILES  ['uploaded_file']['tmp_name']));
  16.         $size = intval($_FILES['uploaded_file']['size']);
  17.  
  18.         // Create the SQL query
  19.         $query = "
  20.             INSERT INTO `file` (
  21.                 `name`, `mime`, `size`, `data`, `created`
  22.             )
  23.             VALUES (
  24.                 '{$name}', '{$mime}', {$size}, '{$data}', NOW()
  25.             )";
  26.  
  27.         // Execute the query
  28.         $result = $dbLink->query($query);
  29.  
  30.         // Check if it was successfull
  31.         if($result) {
  32.             echo 'Success! Your file was successfully added!';
  33.         }
  34.         else {
  35.             echo 'Error! Failed to insert the file'
  36.                . "<pre>{$dbLink->error}</pre>";
  37.         }
  38.     }
  39.     else {
  40.         echo 'An error accured while the file was being uploaded. '
  41.            . 'Error code: '. intval($_FILES['uploaded_file']['error']);
  42.     }
  43.  
  44.     // Close the mysql connection
  45.     $dbLink->close();
  46. }
  47. else {
  48.     echo 'Error! A file was not sent!';
  49. }
  50.  
  51. // Echo a link back to the main page
  52. echo '<p>Click <a href="index.html">here</a> to go back</p>';
  53. ?>
  54.  
  55.  
Phase 3: Listing all existing files
So, now that we have a couple of files in our database, we need to create a list of files and link them so they can be downloaded:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Connect to the database
  3. $dbLink = new mysqli('127.0.0.1', 'user', 'pwd', 'myTable');
  4. if(mysqli_connect_errno()) {
  5.     die("MySQL connection failed: ". mysqli_connect_error());
  6. }
  7.  
  8. // Query for a list of all existing files
  9. $sql = 'SELECT `id`, `name`, `mime`, `size`, `created` FROM `file`';
  10. $result = $dbLink->query($sql);
  11.  
  12. // Check if it was successfull
  13. if($result) {
  14.     // Make sure there are some files in there
  15.     if($result->num_rows == 0) {
  16.         echo '<p>There are no files in the database</p>';
  17.     }
  18.     else {
  19.         // Print the top of a table
  20.         echo '<table width="100%">
  21.                 <tr>
  22.                     <td><b>Name</b></td>
  23.                     <td><b>Mime</b></td>
  24.                     <td><b>Size (bytes)</b></td>
  25.                     <td><b>Created</b></td>
  26.                     <td><b>&nbsp;</b></td>
  27.                 </tr>';
  28.  
  29.         // Print each file
  30.         while($row = $result->fetch_assoc()) {
  31.             echo "
  32.                 <tr>
  33.                     <td>{$row['name']}</td>
  34.                     <td>{$row['mime']}</td>
  35.                     <td>{$row['size']}</td>
  36.                     <td>{$row['created']}</td>
  37.                     <td><a href='get_file.php?id={$row['id']}'>Download</a></td>
  38.                 </tr>";
  39.         }
  40.  
  41.         // Close table
  42.         echo '</table>';
  43.     }
  44.  
  45.     // Free the result
  46.     $result->free();
  47. }
  48. else
  49. {
  50.     echo 'Error! SQL query failed:';
  51.     echo "<pre>{$dbLink->error}</pre>";
  52. }
  53.  
  54. // Close the mysql connection
  55. $dbLink->close();
  56. ?>
Phase 4: Downloading a file
This part is the one that usually causes the most confusion.

To really understand how this works, you must understand how your browser downloads files. When a browser requests a file from a HTTP server, the server response will include information on what exactly it contains. These bits of information are called headers. The headers usually include information on the type of data being sent, the size of the response, and in the case of files, the name of the file.

There are of course a lot of other headers, which I will not cover here, but it is worth looking into!

Now, this code. We start simply by reading the ID sent by the link in phase 3. If the ID is valid, we fetch the information on the file who's ID we received, send the headers, and finally send the file data:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Make sure an ID was passed
  3. if(isset($_GET['id'])) {
  4. // Get the ID
  5.     $id = intval($_GET['id']);
  6.  
  7.     // Make sure the ID is in fact a valid ID
  8.     if($id <= 0) {
  9.         die('The ID is invalid!');
  10.     }
  11.     else {
  12.         // Connect to the database
  13.         $dbLink = new mysqli('127.0.0.1', 'user', 'pwd', 'myTable');
  14.         if(mysqli_connect_errno()) {
  15.             die("MySQL connection failed: ". mysqli_connect_error());
  16.         }
  17.  
  18.         // Fetch the file information
  19.         $query = "
  20.             SELECT `mime`, `name`, `size`, `data`
  21.             FROM `file`
  22.             WHERE `id` = {$id}";
  23.         $result = $dbLink->query($query);
  24.  
  25.         if($result) {
  26.             // Make sure the result is valid
  27.             if($result->num_rows == 1) {
  28.             // Get the row
  29.                 $row = mysqli_fetch_assoc($result);
  30.  
  31.                 // Print headers
  32.                 header("Content-Type: ". $row['mime']);
  33.                 header("Content-Length: ". $row['size']);
  34.                 header("Content-Disposition: attachment; filename=". $row['name']);
  35.  
  36.                 // Print data
  37.                 echo $row['data'];
  38.             }
  39.             else {
  40.                 echo 'Error! No image exists with that ID.';
  41.             }
  42.  
  43.             // Free the mysqli resources
  44.             @mysqli_free_result($result);
  45.         }
  46.         else {
  47.             echo "Error! Query failed: <pre>{$dbLink->error}</pre>";
  48.         }
  49.         @mysqli_close($dbLink);
  50.     }
  51. }
  52. else {
  53.     echo 'Error! No ID was passed.';
  54. }
  55. ?>
Any decent browser should be able to read the headers and understand what type of file this is, and that it is to be downloaded, not opened.

The finish line
So, as you see, this is not as complex as one might think.

This code is of course only written for demonstration purposes and I would not recommend using it without adding a little extra security. Un-edited, this code would basically allow anybody to upload anything to your server, which is not a good idea!

I hope this has been helpful, and I wish you all the best.

See you around,
- Atli Þór

Revisions
  • August 20th, 2008 - Replaced the old mysql functions with the improved mysqli functions.
  • December 12th, 2009 - Updated the introduction to include a bit more detail on the pros and cons of this method. Also improved the code structure a bit. Replaced the mysqli procedural functions with their OOP counterparts. (Thanks to kovik for pointing out the need for these changes!)
Nov 23 '07
221 366812
Atli
5,058 Expert 4TB
@sachin8289
This is a configuration issue with MySQL. By default the largest "packet" you can send at one time is 1MB. You need to edit the server's configuration file to allow a bigger packet to be received.

You can find more details here, in the manual:
C.5.2.10. Packet too large
Apr 7 '12 #151
hey atli , i tried for downloading all types of files and it works also.
But the problem is that it does'nt shows the contents/data of that particular file.
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php
  3.  
  4. include('config.php');
  5. $filename=$_GET['fname'];
  6. $ctype=$_GET['ctype'];
  7. $size=$_GET['size'];
  8. /* echo $filename;
  9. echo $ctype;
  10. echo $size; */
  11. $tmp = explode(".",$filename); 
  12. switch ($tmp[count($tmp)-1]) 
  13.   case "pdf": $ctype="application/pdf"; break; 
  14.   case "exe": $ctype="application/octet-stream"; break; 
  15.   case "zip": $ctype="application/zip"; break; 
  16.   case "docx": 
  17.   case "doc": $ctype="application/msword"; break; 
  18.   case "csv": 
  19.   case "xls": 
  20.   case "xlsx": $ctype="application/vnd.ms-excel"; break; 
  21.   case "ppt": $ctype="application/vnd.ms-powerpoint"; break; 
  22.   case "gif": $ctype="image/gif"; break; 
  23.   case "png": $ctype="image/png"; break; 
  24.   case "jpeg": 
  25.   case "jpg": $ctype="image/jpg"; break; 
  26.   case "tif": 
  27.   case "tiff": $ctype="image/tiff"; break; 
  28.   case "psd": $ctype="image/psd"; break; 
  29.   case "bmp": $ctype="image/bmp"; break; 
  30.   case "ico": $ctype="image/vnd.microsoft.icon"; break; 
  31.   default: $ctype="application/force-download"; 
  32.  
  33. $path=$filename;
  34.  
  35. header("Pragma: public"); // required 
  36. header("Expires: 0"); 
  37. header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
  38. header("Cache-Control: private",false); // required for certain browsers 
  39. header("Content-Type: $ctype"); 
  40. header("Content-Disposition: attachment; filename=$path"); 
  41. header("Content-Transfer-Encoding: binary"); 
  42. header("Content-Length: ".$size); 
  43. ob_clean(); 
  44. flush(); 
  45. readfile($path);
  46. ?>
  47.  
  48.  
can you sort with this error..............
Aug 31 '12 #152
Hello,

I now this is old script, but this is what I really need.
Im beginner and I tried to edit this, I want mysql, and everything works fine except 'get_file.php'. It says 'Error! No image exists with that ID.'; I cant get ID
Please can you help me with this.

I will paste my code, if you have a time please look into that and help.
Mar 8 '13 #153
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  // Make sure an ID was passed
  3.  if(isset($_GET['id'])) {
  4.  // Get the ID
  5.      $id = intval($_GET['id']);
  6.  
  7.      // Make sure the ID is in fact a valid ID
  8.      if($id <= 0) {
  9.          die('The ID is invalid!');
  10.      }
  11.      else {
  12.          $dbLink =  $dbLink = mysql_connect("localhost", "root", "") or die (mysql_error());
  13.  
  14. mysql_select_db("databese1", $dbLink) or die ("Could not connect to database!");
  15.  
  16.          $query = "
  17.              SELECT `mime`, `name`, `size`, `data`
  18.              FROM `file`
  19.              WHERE `id` = {$id}";
  20.         // $result = $dbLink->query($query);
  21.  
  22.  $result = mysql_query ($query, $dbLink);
  23.  
  24.          if($result) {
  25.              // Make sure the result is valid
  26.              if($result == 1) {
  27.                  $row = mysql_fetch_assoc($result);
  28.  
  29.                  header("Content-Type: ". $row['mime']);
  30.                  header("Content-Length: ". $row['size']);
  31.                  header("Content-Disposition: attachment; filename=". $row['name']);
  32.  
  33.                  // Print data
  34.                  echo $row['data'];
  35.              }
  36.              else {
  37.                  echo 'Error! No image exists with that ID.';
  38.              }
  39.  
  40.              // Free the mysqli resources
  41.              @mysql_free_result($result);
  42.          }
  43.          else {
  44.              echo "Error! Query failed:";
  45.          }
  46.          mysql_close($dbLink);
  47.      }
  48.  }
  49.  else {
  50.      echo 'Error! No ID was passed.';
  51.  }
  52.  ?>
Mar 8 '13 #154
Atli
5,058 Expert 4TB
Hey.

Line #26 of your code. It should be comparing the number of rows in the result set to the number 1. As it is there, however, it's just comparing the result set reference to 1. Look into the mysql_num_rows function.

One question though. Why would you downgrade the code to use the old MySQL API, when the original code is already using the more modern MySQLi extension? (Granted, it's old enough to be using the procedural MySQLi functions, and without prepared statements, but still...)
Mar 9 '13 #155
Thanks for replay, sorry for my poor english.
Can you suggest me any pagination script that will work on this mysqli script. I tried to use some pagination scripts but it wont work, and same pagination scripts work nice with other upload scripts.
Mar 11 '13 #156
Ammu
78
I have tried it and works properly
Thank you so much atli for this useful article.
Mar 13 '13 #157
strelc
1
Insert this
Expand|Select|Wrap|Line Numbers
  1. while (@ob_end_clean());
line before
Expand|Select|Wrap|Line Numbers
  1.  header("Content-Disposition: attachment; filename=". $row['name']);
and download will work like a charm ...
Apr 6 '13 #158
hi, wen i download my file, i cant able to open it.. its get corrupted.. may i knw wat coud be the error.. its wrking for text files.. but not for pdf/image/ppt/doc...
Apr 10 '13 #159
Atli
5,058 Expert 4TB
Likely some warning or notice in PHP is being printed into the output. Try opening the corrupt file in a text editor like Notepad (make sure it's not too big, or it'll freeze the editor!) and look for error messages in the binary stuff. The text editor should be able to see the text message in the binary and display it as text.
Apr 12 '13 #160
AWSOME! Thankyou so much for share! The code works..!!
Jun 15 '13 #161
boss , i got this error , where is the problem ? .. for download script only (get_file.php)

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\test2\get_file.php:2) in C:\xampp\htdocs\test2\get_file.php on line 33

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\test2\get_file.php:2) in C:\xampp\htdocs\test2\get_file.php on line 34

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\test2\get_file.php:2) in C:\xampp\htdocs\test2\get_file.php on line 35

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. // Make sure an ID was passed
  3. if(isset($_GET['id'])) {
  4. // Get the ID
  5.     $id = intval($_GET['id']);
  6.  
  7.     // Make sure the ID is in fact a valid ID
  8.     if($id <= 0) {
  9.         die('The ID is invalid!');
  10.     }
  11.     else {
  12.         // Connect to the database
  13.         $dbLink = new mysqli('127.0.0.1', 'root', '', 'file');
  14.         if(mysqli_connect_errno()) {
  15.             die("MySQL connection failed: ". mysqli_connect_error());
  16.         }
  17.  
  18.         // Fetch the file information
  19.         $query = "
  20.             SELECT `mime`, `name`, `size`, `data`
  21.             FROM `file`
  22.             WHERE `id` = {$id}";
  23.         $result = $dbLink->query($query);
  24.  
  25.         if($result) {
  26.             // Make sure the result is valid
  27.             if($result->num_rows == 1) {
  28.             // Get the row
  29.                 $row = mysqli_fetch_assoc($result);
  30.  
  31.                 // Print headers
  32.                header("Content-Type: ". $row['mime']);
  33.                header("Content-Length: ". $row['size']);
  34.                 header("Content-Disposition: attachment; filename=". $row['name']);
  35.  
  36.                 // Print data
  37.                 echo $row['data'];
  38.             }
  39.             else {
  40.                 echo 'Error! No image exists with that ID.';
  41.             }
  42.  
  43.             // Free the mysqli resources
  44.             @mysqli_free_result($result);
  45.         }
  46.         else {
  47.             echo "Error! Query failed: <pre>{$dbLink->error}</pre>";
  48.         }
  49.         @mysqli_close($dbLink);
  50.     }
  51. }
  52. else {
  53.     echo 'Error! No ID was passed.';
  54. }
  55. ?>
  56.  
Jun 23 '13 #162
hanugeek :

share with me the download code ?
Jun 23 '13 #163
Atli
5,058 Expert 4TB
abdulrahim0704. Those errors indicate that something is being printed before the code starts. Note that NOTHING can be placed before the opening <?php tag in my example code. If there is so much as a space, then what you posted will happen.

I've also seen this happen when people try to use Unicode files for their PHP code (UTF-8, specifically), including the BOM (Byte order mark) character. PHP doesn't handle Unicode, so the file must be saved as ASCII. If you are unsure on this point, try installing Notepad++, opening the file, and using the "Encoding" menu to convert the file to ASCII.
Jun 24 '13 #164
Atlii thanks for the help :) now it work perfectly !!!!! awesome ! hahahaha...
Jun 24 '13 #165
I need help after i used this code was still getting this errors

Warning: Cannot modify header information - headers already sent by (output started at /home/zivamaho/public_html/get_file.php:1) in /home/zivamaho/public_html/get_file.php on line 32

Warning: Cannot modify header information - headers already sent by (output started at /home/zivamaho/public_html/get_file.php:1) in /home/zivamaho/public_html/get_file.php on line 33

Warning: Cannot modify header information - headers already sent by (output started at /home/zivamaho/public_html/get_file.php:1) in /home/zivamaho/public_html/get_file.php on line 34
/tmp/phpR9kTog


this is my code: i used it on cpanel upload but got the above errors. Pls help me out

Expand|Select|Wrap|Line Numbers
  1.  <?php
  2.     // Make sure an ID was passed
  3.     if(isset($_GET['id'])) {
  4.     // Get the ID
  5.         $id = intval($_GET['id']);
  6.  
  7.         // Make sure the ID is in fact a valid ID
  8.         if($id <= 0) {
  9.             die('The ID is invalid!');
  10.         }
  11.         else {
  12.             // Connect to the database
  13.             $dbLink = mysqli_connect('localhost', 'zivamaho_data', 'hospitality', 'zivamaho_hotel');
  14.             if(mysqli_connect_errno()) {
  15.                 die("MySQL connection failed: ". mysqli_connect_error());
  16.             }
  17.  
  18.             // Fetch the file information
  19.             $query = "
  20.                 SELECT first_name,last_name,email,address,phone,mime, name, size, data
  21.                 FROM file
  22.                 WHERE `id` = {$id}";
  23.             $result = $dbLink->query($query);
  24.  
  25.             if($result) {
  26.                 // Make sure the result is valid
  27.                 if($result->num_rows == 1) {
  28.                 // Get the row
  29.                     $row = mysqli_fetch_assoc($result);
  30.  
  31.                     // Print headers
  32.                     header("Content-Type:".$row['mime']);
  33.                     header("Content-Length:".$row['size']);
  34.                     header("Content-Disposition:attachment;filename=".$row['name']);
  35.  
  36.  
  37.                     // Print data
  38.                     echo $row['data'];
  39.                 }
  40.                 else {
  41.                     echo 'Error! No image exists with that ID.';
  42.                 }
  43.  
  44.                 // Free the mysqli resources
  45.                 @mysqli_free_result($result);
  46.             }
  47.             else {
  48.                 echo "Error! Query failed: <pre>{$dbLink->error}</pre>";
  49.             }
  50.             @mysqli_close($dbLink);
  51.         }
  52.     }
  53.     else {
  54.         echo 'Error! No ID was passed.';
  55.     }
  56.     ?>
Jun 28 '13 #166
Atli
5,058 Expert 4TB
Hey, chikodi. This is the exact same problem abdulrahim0704 was having in the posts above yours. The same advice I gave him applies to you as well.

Also, use [code] tags when posting code. Otherwise the code is more or less unreadable.
Jun 29 '13 #167
hi, im getting this error please help me when i upload file
Error! A file was not sent!
Aug 12 '13 #168
Atli
5,058 Expert 4TB
Well, clearly a file isn't being sent. Beyond that I can't say without knowing what you did. Make sure your form is written correctly, specifically the "enctype" attribute on the actual <form> element, and the name of the input elements.
Aug 13 '13 #169
hi guys, i used the code and its work just fine, but when it come to download pdf file it just print in the screen garbage no errors. also checked no white space no bom characters, i don't know whats going on. im have been trying to solve this for days but couldn't please some help required here.
"û<؟أشX .VبUضà-ى6?N<}oيز:5¸`@ô›‎ژHصoءµپ_ز=ح§ƒؤ،l*ô¸ƒo©#é{ ‡ّ_ںn ¶*'ًE‏–"ضçَùüê=،yO©§™ےWد>|x(U§ںً|‡çسzDA!‚²ـXé ¹"üےjآـ›ٌُ÷4B/ْA حڈûWش قكƒcôےoîJS¹7ز,ےہƒُژAْ‹}÷(S–PO6$وك_÷*7<ںإ¾–$¦2 }ƒث×ژsهہyôو–>]7x‹r,ھ.Mإ‏¶#‹¼ـً°÷ڈإpnO‹ ~؟ش›‹s‎üûxً ُا’ü[ـ~yدم‰‚ہhE6‎F×'‹?[كگ9‏¶é¬g?لٍح~كِqص´p‏güلéüےcٹآهx· `>„ے^uِأ*>‡ـacآھéٌْp@â÷مپے°؛‹^êi <ءوےظ·à}@ے_“اضاڈpقTC‎ Sp.l$p/بµہ_n,کُ؟êےWّz،R?دزaس*AْZàR??[‎l'غlً*كُثq‏ٌ{ƒnx؟éاµ4°،نعكV$ط*Gْضْـ}~ œ@– :—’?گ9°±ےôçغèôب'ٍَے7*?oZ"¸é*ًءTدسڈê-ُںد6ےy»Dkvyâآ÷üڈ،½ے‏¾ض5q¢¾‘~lOم‎ê×؟ْك×ْpںھ§à¶ –&نـ8مübGّ‏¯چ†@#¦،§§ْ؟/çز2ھMہْ?Q‎AـƒہoOِچ½Cع~¦3ْپnA$^ق‘ُ ¶üے¼ûYVGاسژ«¯إے*يا<~*سu+ثپù ‎O#ً@¹"كO§معش8ô¦?e:£ ڈثث‎YٍٍéZ،ƒXYژ£¦ہپoOô؟مè@¹·ُ؟´*g²ْt…S`>ں[sُ¨?Okٹب‰²‚؟ُ¹¸½يحاوئ×½د´½U4ژLq«31V4ynGçM›شI ¨؟مپيtDSˆء¯س‡==xôرسڈ “‎_>گُٹ9 ?ط²H½¯ù½ى?¯زuê£êéْ‘ù؟زكںًوقئظ¯& ز`2§…ڑX é 1!§ٌ…م›‚x<*.[هêü×/گ*ئذ ¾،4آy‹’ أ¨\r,dbْ‏ش ë8?¶؛پ(r ‹PH§ “ا×?ië^خIXـƒè؟çüة#ü½عهQ›ْ~€‎snئؤںiJ¥$بyµح ڈ§écد?ï›Kطپا3€ع8Pا1¹”¨r„@b¦چعأR$•=د©Wذڑµ$¯°±û £¢z؛پ+w& ڈَ7ٹŒe²ً,•“‚=0ء#ئfkحè1%—Y]V7Naعرd"هdز2ecڑj&‚**#‹pذُ¦±œSRھjj)b|دددگَé®X5 ٌrاWWV¢I‎Bاًط[ْ{ê—fn\ث7ًœ[#`Y‏زٹھp£‚ڑ4+oشo`"

Expand|Select|Wrap|Line Numbers
  1.  <?php
  2.  
  3.  
  4. $company =$_GET['company'];
  5.  
  6.  
  7. // Make sure an ID was passed
  8. if(isset($_GET['id'])) {
  9. // Get the ID
  10.     $id = intval($_GET['id']);
  11.  
  12.     // Make sure the ID is in fact a valid ID
  13.     if($id <= 0) {
  14.         die('The ID is invalid!');
  15.     }
  16.     else {
  17.         // Connect to the database
  18.         $dbLink = new mysqli('localhost', 'sqldata', 'sqldata', 'balhaf');
  19.         if(mysqli_connect_errno()) {
  20.             die("MySQL connection failed: ". mysqli_connect_error());
  21.         }
  22.  
  23.         // Fetch the file information
  24.         $query = "
  25.             SELECT mime, name, size, data
  26.             FROM $company
  27.             WHERE id = $id";
  28.         $result = $dbLink->query($query);
  29.  
  30.         if($result) {
  31.             // Make sure the result is valid
  32.             if($result->num_rows == 1) {
  33.             // Get the row
  34.                 $row = mysqli_fetch_assoc($result);
  35.  
  36.                 // Print headers
  37.                 header("Content-Type: ". $row['mime']);
  38.                 header("Content-Length: ". $row['size']);
  39.                 header("Content-Disposition: attachment; filename=". $row['name']);
  40.                 // Print data
  41.                 echo $row['data'];
  42.             }
  43.             else {
  44.          echo 'Error! No image exists with that ID.';
  45.             }
  46.  
  47.             // Free the mysqli resources
  48.             @mysqli_free_result($result);
  49.         }
  50.         else {
  51.             echo "Error! Query failed: <pre>{$dbLink->error}</pre>";
  52.         }
  53.         @mysqli_close($dbLink);
  54.     }
  55. }
  56. else {
  57.     echo 'Error! No ID was passed.';
  58. }
  59. ?>
  60.  
Sep 9 '13 #170
Atli
5,058 Expert 4TB
hadinetcat, what is the actual Content-Type sent with the request? Use a development tool like Firebug to examine the request and check out exactly what it is. - If it's printing stuff to the screen, it's not setting the headers correctly. Otherwise you'd just end up with a corrupt PDF download.
Sep 10 '13 #171
Atli, the download work fine in firefox mozilla and google chrome but not in IE 10. i have tried everything i also tried
Expand|Select|Wrap|Line Numbers
  1.  if(strstr($_SERVER["HTTP_USER_AGENT"],"MSIE")==false) {
  2.  
but not helping.. im still getting garbage when using IE 10.
Sep 10 '13 #172
Atli
5,058 Expert 4TB
Well, garbage begets garbage... :)

Seriously though, you have not yet answered the question I posed in my last post. What content type is the browser receiving?! That is the key piece of info needed here. - All the browsers, including IE10, have developer tools that can tell you that. Use them!

Also, I don't know what exactly you think that line of code is meant to do, but I can't see any reason why you'd use that in this context. In fact, browser sniffing code is generally a bad idea. It should be avoided at all costs!
Sep 10 '13 #173
Atli, i used ieHTTPHeaders to examine the header but it show empty in IE 10, also i used Firebug in firefox mozilla it show Content-Type: application/pdf which is working fine, but not in IE 10.. what shell i do next ?? to fix my problem
Sep 11 '13 #174
Thanks for the code!
I am however getting the error "file was not sent" very often and only with specific files any idea why? I am currently testing with your code completely unedited with a server on my lan.

for example I get this error with any .cr2 file (canon raw image file) some .pdf's

I also get "An error accured while the file was being uploaded. Error code: 1" with many files but cant figure out what error code 1 means :(

any help would be greatly appreciated!

edit: it seems to be any file larger than about 2mb in size that throw one of the two errors so far I cant find any other pattern
Sep 22 '13 #175
Atli
5,058 Expert 4TB
The manual entry on uploads should be your first stop. (In fact it's pretty much the result returned by Google when asking it any query about PHP file uploads.) - The very first paragraph in the Common Pitfalls section explain the problem, as does the description of error code 1 in the Error Messages Explained section.
Sep 23 '13 #176
tnshum
1
I try the code, it works.
However, when I try to upload the file up to 1MB, it wil has an error as below:
Error! Failed to insert the file
MySQL server has gone away
I want to know how to upload more than 1MB file to mysql?
Oct 8 '13 #177
shayar
1
where upload file stored in the computer?
Nov 4 '13 #178
Atli
5,058 Expert 4TB
@shayar. To answer that, let me quote you the title of this article:
Uploading files into a MySQL database using PHP
If you are fuzzy on the above concept - versus the normal method of storing files on the file-system - then I strongly suggest you do not use this technique. It is not something you should do without understanding what it is doing and why it's being done that way.
Nov 7 '13 #179
hi.. thank you for posting this tutorial, in my case it works in almost all files except for fetching the image (jpg format) from database.
Dec 14 '13 #180
thanks! this is very helpful. =)
Dec 17 '13 #181
hi,

when I download file, there is entire html code in my download file. My code is same as in article above so I don't know where the problem would be, so please help.
Dec 18 '13 #182
rsoni
1
Thank you so much...!!
Mar 11 '14 #183
pls i got dis error "Got a packet bigger than 'max_allowed_packet' bytes," wat can i do
Mar 17 '14 #184
Atli
5,058 Expert 4TB
MySQL limits the max size of packets it can receive, using the max_allowed_packet directive. Depending on your server version, it can be either 1MB or 4MB by default.

If you want to submit binary files larger than that, you need to change this to a higher value in your MySQL server's configuration file. How exactly you do that depends on your platform. I suggest you use Google to find that out; it's a common question that has already been answered a few thousand times out there.
Mar 17 '14 #185
i have change the default max_packet_allowed to 128mbbut still received same error
Mar 20 '14 #186
jakai
1
Sir, In get_file.php i got this error The ID is invalid!
Mar 23 '14 #187
hey atil , bro u helped a lot .... the files in the database are viewing i.e working well till #53 but error is coming in the download part....i.e after #56
it always show no ID was passed
Expand|Select|Wrap|Line Numbers
  1.  <?php
  2.     // Connect to the database
  3.     //mysql_connect(""localhost","root",""") = $dblink   
  4.     $dbLink = new mysqli("localhost", "root", "", 'iitm');
  5.     if(mysqli_connect_errno()) {
  6.         die("MySQL connection failed: ". mysqli_connect_error());
  7.     }
  8.  
  9.     // Query for a list of all existing files
  10.     $sql = 'SELECT `file_id`, `file_name` FROM `files`';
  11.     $result = $dbLink->query($sql);
  12.  
  13.     // Check if it was successfull
  14.     if($result) {
  15.         // Make sure there are some files in there
  16.         if($result->num_rows == 0) {
  17.             echo '<p>There are no files in the database</p>';
  18.         }
  19.         else {
  20.             // Print the top of a table
  21.             echo '<table width="100%">
  22.                     <tr>
  23.                         <td><b>Name</b></td>
  24.  
  25.  
  26.                     </tr>';
  27.  
  28.             // Print each file
  29.             while($row = $result->fetch_assoc()) {
  30.                 echo "
  31.                     <tr>
  32.                         <td>{$row['file_name']}</td>
  33.  
  34.                         <td><a href='get_file.php?id={$row['file_id']}'>Download</a></td>
  35.                     </tr>";
  36.             }
  37.  
  38.             // Close table
  39.             echo '</table>';
  40.         }
  41.  
  42.         // Free the result
  43.         $result->free();
  44.     }
  45.     else
  46.     {
  47.         echo 'Error! SQL query failed:';
  48.         echo "<pre>{$dbLink->error}</pre>";
  49.     }
  50.  
  51.     // Close the mysql connection
  52.     $dbLink->close();
  53.     ?>
  54.  
  55.  
  56.  
  57.     <?php
  58.     // Make sure an ID was passed
  59.     if(isset($_GET['file_id'])) {
  60.     // Get the ID
  61.         $id = intval($_GET['file_id']);
  62.  
  63.         // Make sure the ID is in fact a valid ID
  64.         if($id <= 0) {
  65.             die('The ID is invalid!');
  66.         }
  67.         else {
  68.             // Connect to the database
  69.             $dbLink = new mysqli("localhost", "root", "", 'iitm');
  70.             if(mysqli_connect_errno()) {
  71.                 die("MySQL connection failed: ". mysqli_connect_error());
  72.             }
  73.  
  74.             // Fetch the file information
  75.             $query = "
  76.                 SELECT `name`
  77.                 FROM `files`
  78.                 WHERE `file_id` = {$id}";
  79.             $result = $dbLink->query($query);
  80.  
  81.             if($result) {
  82.                 // Make sure the result is valid
  83.                 if($result->num_rows == 1) {
  84.                 // Get the row
  85.                     $row = mysqli_fetch_assoc($result);
  86.  
  87.                     // Print headers
  88.                    while (@ob_end_clean());
  89.                     header("Content-Disposition: attachment; filename=". $row['file_name']);
  90.  
  91.                     // Print data
  92.                     echo $row['file'];
  93.                 }
  94.                 else {
  95.                     echo 'Error! No file exists with that ID.';
  96.                 }
  97.  
  98.                 // Free the mysqli resources
  99.                 @mysqli_free_result($result);
  100.             }
  101.             else {
  102.                 echo "Error! Query failed: <pre>{$dbLink->error}</pre>";
  103.             }
  104.             @mysqli_close($dbLink);
  105.         }
  106.     }
  107.     else {
  108.         echo 'Error! No ID was passed.';
  109.     }
  110.     ?>
  111.  
Apr 8 '14 #188
Finally Got after searching all websites in 2 days thank yu dude....
Apr 19 '14 #189
hello everyone can ask themselves how the images from the database to the screen from the addition of database files his (her) Atli
May 30 '14 #190
jumper
1
<?php

// Make sure an ID was passed
if(isset($_GET['id'])) {
// Get the ID
$id = intval($_GET['id']);

// Make sure the ID is in fact a valid ID
if($id <= 0) {
die('The ID is invalid!');
}
else {
// Connect to the database
$dbLink = new mysqli("127.0.0.1", "", "", "");
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}

// Fetch the file information
$query = "
SELECT `mime`, `name`, `size`, `data`
FROM `file`
WHERE `id` = {$id}";
$result = $dbLink->query($query);

if($result) {
// Make sure the result is valid
if($result->num_rows == 1) {

// Get the row
// $row = mysqli_num_rows($result);

// Print headers
header("Content-Type: ". $row['mime']);
header("Content-Length: ". $row['size']);
header("Content-Disposition: attachment; filename=". $row['name']);
echo $name;
// Print data
echo $row['data'];
}
else {
echo 'Error! No image exists with that ID.';
}

// Free the mysqli resources
@mysqli_free_result($result);
}
else {
echo "Error! Query failed: <pre>{$dbLink->error}</pre>";
}
@mysqli_close($dbLink);
}
}
else {
echo 'Error! No ID was passed.';
}
?>

Please help me to run this code GET FILES
I got an error

Error! No image exists with that ID.
Jun 7 '14 #191
Atli
5,058 Expert 4TB
Have you made sure that the image actually does exist in the database?
Jun 9 '14 #192
delvin
1
Hi Atli,

i'm using your code and it's working. but i have a probrem when i download the file and i open it, my file isn'n like before. now my file already convret with html tag.

how can i fix that?
Jun 16 '14 #193
Dear Atli,

Im using your code aswell, but I got a few problems.

The first file I upload there is no problem with, Its pasted in the DB, and I can download and see it on the files page.

After I uploaded the Second file I do get this error,

Error! No image exists with that ID.

If you want I can paste the code's here, but i copied these one on one, and the only things I did change are the tablenames, and I customized the login settings!

Thanks in advance :)
Aug 15 '14 #194
Just to be sure, Code's over here. I deleted my DB login files!

get_file.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     // Make sure an ID was passed
  3.     if(isset($_GET['id'])) {
  4.     // Get the ID
  5.         $id = intval($_GET['id']);
  6.  
  7.         // Make sure the ID is in fact a valid ID
  8.         if($id <= 0) {
  9.             die('The ID is invalid!');
  10.         }
  11.         else {
  12.             // Connect to the database
  13.             $dbLink = new mysqli('127.0.0.1', '', '', '');
  14.             if(mysqli_connect_errno()) {
  15.                 die("MySQL connection failed: ". mysqli_connect_error());
  16.             }
  17.  
  18.             // Fetch the file information
  19.             $query = "
  20.                 SELECT `mime`, `name`, `size`, `data`
  21.                 FROM `filejtc`
  22.                 WHERE `id` = {$id}";
  23.             $result = $dbLink->query($query);
  24.  
  25.             if($result) {
  26.                 // Make sure the result is valid
  27.                 if($result->num_rows == 1) {
  28.                 // Get the row
  29.                     $row = mysqli_fetch_assoc($result);
  30.  
  31.                   //print headers
  32.                     header("Content-Type: ". $row['mime']);
  33.                     header("Content-Length: ". $row['size']);
  34.                     header("Content-Disposition: attachment; filename=". $row['name']);
  35.  
  36.                     // Print data
  37.                     echo $row['data'];
  38.                 }
  39.                 else {
  40.                     echo 'Error! No image exists with that ID.';
  41.                 }
  42.  
  43.                 // Free the mysqli resources
  44.                 @mysqli_free_result($result);
  45.             }
  46.             else {
  47.                 echo "Error! Query failed: <pre>{$dbLink->error}</pre>";
  48.             }
  49.             @mysqli_close($dbLink);
  50.         }
  51.     }
  52.     else {
  53.         echo 'Error! No ID was passed.';
  54.     }
  55.     ?>
  56.  
  57.  
files.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     // Connect to the database
  3.     $dbLink = new mysqli('127.0.0.1', '', '', '');
  4.     if(mysqli_connect_errno()) {
  5.         die("MySQL connection failed: ". mysqli_connect_error());
  6.     }
  7.  
  8.     // Query for a list of all existing files
  9.     $sql = 'SELECT `id`, `name`, `mime`, `size`, `created` FROM `filejtc`';
  10.     $result = $dbLink->query($sql);
  11.  
  12.     // Check if it was successfull
  13.     if($result) {
  14.         // Make sure there are some files in there
  15.         if($result->num_rows == 0) {
  16.             echo '<p>Er zitten nog geen bestanden in de database!</p>';
  17.         }
  18.         else {
  19.             // Print the top of a table
  20.             echo '<table width="100%">
  21.                     <tr>
  22.                         <td><b>Naam:</b></td>
  23.                         <td><b>Soort bestand:</b></td>
  24.                         <td><b>Grootte (bytes)</b></td>
  25.                         <td><b>Aangemaakt</b></td>
  26.                         <td><b>&nbsp;</b></td>
  27.                     </tr>';
  28.  
  29.             // Print each file
  30.             while($row = $result->fetch_assoc()) {
  31.                 echo "
  32.                     <tr>
  33.                         <td>{$row['name']}</td>
  34.                         <td>{$row['mime']}</td>
  35.                         <td>{$row['size']}</td>
  36.                         <td>{$row['created']}</td>
  37.                         <td><a href='get_file.php?id={$row['id']}'>Download</a></td>
  38.                     </tr>";
  39.             }
  40.  
  41.             // Close table
  42.             echo '</table>';
  43.         }
  44.  
  45.         // Free the result
  46.         $result->free();
  47.     }
  48.     else
  49.     {
  50.         echo 'Error! SQL query failed:';
  51.         echo "<pre>{$dbLink->error}</pre>";
  52.     }
  53.  
  54.     // Close the mysql connection
  55.     $dbLink->close();
  56.     ?>
add_file.php
Expand|Select|Wrap|Line Numbers
  1.     <?php
  2.     // Check if a file has been uploaded
  3.     if(isset($_FILES['uploaded_file'])) {
  4.         // Make sure the file was sent without errors
  5.         if($_FILES['uploaded_file']['error'] == 0) {
  6.             // Connect to the database
  7.             $dbLink = new mysqli('', '', '', '');
  8.             if(mysqli_connect_errno()) {
  9.                 die("MySQL connection failed: ". mysqli_connect_error());
  10.             }
  11.  
  12.             // Gather all required data
  13.             $name = $dbLink->real_escape_string($_FILES['uploaded_file']['name']);
  14.             $mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']);
  15.             $data = $dbLink->real_escape_string(file_get_contents($_FILES  ['uploaded_file']['tmp_name']));
  16.             $size = intval($_FILES['uploaded_file']['size']);
  17.  
  18.             // Create the SQL query
  19.             $query = "
  20.                 INSERT INTO `filejtc` (
  21.                     `name`, `mime`, `size`, `data`, `created`
  22.                 )
  23.                 VALUES (
  24.                     '{$name}', '{$mime}', {$size}, '{$data}', NOW()
  25.                 )";
  26.  
  27.             // Execute the query
  28.             $result = $dbLink->query($query);
  29.  
  30.             // Check if it was successfull
  31.             if($result) {
  32.                 echo 'Succes! Het bestand is toegevoegt aan de database!';
  33.             }
  34.             else {
  35.                 echo 'Error! Er is wat fout gegaan bij het invoegen aan de database! Probeer opnieuw!'
  36.                    . "<pre>{$dbLink->error}</pre>";
  37.             }
  38.         }
  39.         else {
  40.             echo 'Er is wat fout gegaan tijdens het uploaden, probeer opnieuw! '
  41.                . 'Error code: '. intval($_FILES['uploaded_file']['error']);
  42.         }
  43.  
  44.         // Close the mysql connection
  45.         $dbLink->close();
  46.     }
  47.     else {
  48.         echo 'Error! Er is geen bestand geselecteerd!';
  49.     }
  50.  
  51.     // Echo a link back to the main page
  52.     echo '<p>Klik <a href="../jtc/files.php">HIER</a> om verder te gaan!</p>';
  53.     ?>
Aug 15 '14 #195
Atli
5,058 Expert 4TB
Hey. So the second file is uploaded without error, is listed in the files list with a download link, but then fails to be downloaded saying the ID is invalid?

I see no reason why that would be happening with that code.
Are you sure the image is being uploaded correctly? Have you checked the database entry for it to see if everything is in order?
Aug 15 '14 #196
I think there I found the problem. I am not uploading images, but .DOC / .ODT / .PDF files.. Is there a possibility to fix these?

I have checked the database after I stored some files, and thats working correctly, so there is no problem with the uploading, there only is a problem with get_file.php

By the way, I have got one table with multiple uploaded files, over 8 files or so, and I still get this error, so after the first upload it isnt working anymore.
Aug 16 '14 #197
Atli
5,058 Expert 4TB
There is nothing in the code that's specific to images, a part from the error message. In fact, the error message is wrong to specify it as an image. - I originally wrong this as an image upload script, but made it more general for the article. I seem to have overlooked rewording the error message.

It should work fine with any file type. I tested my original code with a bunch of non-image types. The mime type it provides during the download is the same type it gets from the browser during the upload.

Can you show us the URL of a download link that fails, and the corresponding row in the database?
Aug 16 '14 #198
There we go, this is where it goes wrong, with 2 files in the database. As I see the ID is right, even as the ID of the database is right!

The template plus files.php
http://puu.sh/aVkEb/b9afc3edbb.png

http://revival.huizevisser.nl/rac/get_file.php?id=5 <-- download url
http://puu.sh/aVkGM/995b01ca53.png

phpmyadmin
http://puu.sh/aVkJL/cd69655364.png

__________________________

I think I found the problem.
Didnt fixed it yet as I don't know how, but when i have 3 .txt documents in a database, it keeps working, BUT, when i add a .doc/.docx file, its gonna mess up and stop working.

Preview:
files.php
http://puu.sh/aVlg7/2221694563.png

on click download
http://puu.sh/aVlh1/92b406d684.png

Add .DOCX file (Jaarverslag RAC 2014.docx)
http://puu.sh/aVliE/e69c645322.png

Try to download .DOCX or a txt file,
http://puu.sh/aVlsW/d8a1892f8b.png

database:
http://puu.sh/aVluw/072c4390dd.png

Hope this is enough information!
skype: gekke_dj
Aug 16 '14 #199
Atli
5,058 Expert 4TB
Might have something to do with the size of the files. The DOCX file in there is significantly larger than the text files.

Try calling $result->store_result(); right after the if ($result) in the get_file script.

I usually prefer PDO over MySQLi, so I'm not certain about this, but according to the MySQLi docs the num_rows function may not work correctly unless you store the result. If there is a size barrier on what it automatically stores and what it doesn't, the larger size of the DOC/DOCX/PDF files may be causing the num_rows function to return 0 even when there is data, thus causing this error.
Aug 17 '14 #200

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: hdf | last post by:
hi i have problems uploading my database using phpmyadmin n i want to load it using the ssh termal in setd of phpmyadmin. can anyone hlp
11
by: menmysql | last post by:
i am getting the following error while connecting mysql database using jsp java.sql.SQLException: Communication link failure: Bad handshake can any one tell what is the actual problem
8
by: menmysql | last post by:
i am not bale to solve this problem since two weeks i am trying to access records from mysql database using jsp. inside this jsp program i wrote all my JDBC code. it is working very nicely and...
9
by: christopher_board | last post by:
Hi all. I am trying to connect to a MySQL Database using PHP on a local machine using locahost. I am using the following code <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass =...
1
by: ganeshg | last post by:
Hai All, Please let me know how to insert audio files into mysql database using .net. Thanking you.....
3
by: Suresh P | last post by:
Hi All, I tried to access the mysql database in ODBC using ip address and username/password. It returns, "cannot connect to MySQL server on IP ADDRESS(10060)". This could be related to Firewall...
1
by: nadeenahmed | last post by:
I have Connected to a MySQL Database using a neatbeans editor. Now, I want to use that same database I created earlier on another pc. Can anyone help and tell me how that is done, please? Thank...
6
by: mfaisalwarraich | last post by:
Hi everyone, I am trying to add multiple pinpoint to google map using Lon/Lat. All addresses will be fetched from mysql database using PHP. I have looked at google and searched for it on...
1
by: santhanalakshmi | last post by:
Hi, I wrote some coding, to import excel data in mysql database using PHP Script? But my script, its not all inserting the excel data in mysql database. I don't know, what mistake did i made?...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.