Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>That is <strong>not</strong> secure. At the very least you need to verify that the file was indeed an uploaded file and not a file already on the server like /etc/passwd. To do that you need to use <code>is_uploaded_file()</code>.</p> <p>Example:</p> <pre><code>&lt;?php if (is_uploaded_file($_FILES['file1']['tmp_name'])) { $tmp_name1 = $_FILES['file1']['tmp_name']; if (($handle = fopen($tmp_name1, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); // SQL insert statement } fclose($handle); } } </code></pre> <p>?> </p> <p>You also should rename any file uploaded to your server as leaving the name of the file unchanged could lead to remote file attack where someone executes the file on your server. </p> <p>Finally, if the file upload is only supposed to accept certain file type, like images, then you should definitely check to make sure the file is actually an image. At the very least check the file extension to make sure it is a .png, .gif, .jpg, etc. If it is a .exe then reject it immediately as it is obviously is not an image and thus of no use to you.</p> <pre><code>&lt;?php if (is_uploaded_file($_FILES['file1']['tmp_name'])) { $allowedExtensions = array("txt","csv","htm","html","xml","css","doc","xls","rtf","ppt","pdf","swf","flv","avi","wmv","mov","jpg","jpeg","gif","png"); if (!in_array(end(explode(".", strtolower($_FILES['file1']['name']))), $allowedExtensions)) { // Bad file type. Error! } else { $tmp_name1 = $_FILES['file1']['tmp_name']; if (($handle = fopen($tmp_name1, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); // SQL insert statement } fclose($handle); } } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload