Note that there are some explanatory texts on larger screens.

plurals
  1. POupload file using ajax like facebook uploading
    primarykey
    data
    text
    <p>My problem is, I want to upload a csv file without pressing a submit button and I used ajax for that case. But now, their is something errors appear, and the error said fopen() Filename cannot be empty. But I already get the file value that I want, but the $_FILES[$fie]['tmp_name'] can't read this value. But if I attach the variable in an alert() they display the exact filename. This is my sample codes.</p> <p>This is the html:</p> <pre><code>&lt;form id="Form2"&gt; &lt;input type="file" id="fie" /&gt; &lt;/form&gt; </code></pre> <p>this is the javascript:</p> <pre><code>&lt;script style="text/javascript"&gt; $(function(){ $('#Form2').change(function(e){ e.preventDefault(); var sub = document.getElementById("fie").files[0].name; if($('#cat1').hasClass('show')){ $('#cat1').hide(); $('#cat2').html("&lt;img src='pb1.gif' /&gt;"); $.ajax({ url:'uploading.php', action:'get', data: 'fie='+sub, success: function(data){ $('#cat2').html(data); } }); } }); }); &lt;/script&gt; </code></pre> <p>This is the Php: uploading.php</p> <pre><code>&lt;?php include("conn.php"); //assuming that connected to a database. if (isset($_GET['fie'])) { echo "&lt;script&gt;alert('".$_GET['fie']."')&lt;/script&gt;";//IN ALERT THEY EXECUTE THE EXACT VALUE OF THE FILE I INPUT $fie = $_GET['fie']; $file = $_FILES[$fie]['tmp_name']; //PROBLEM IS THIS. THEY CAN'T READ THE VALUE AND TELL THEIR IS NO FILE. $handle = fopen($file,'r') or die ('Cannot open file'); fgets($handle); do { if (isset($data[0])) { mysql_query("INSERT INTO tbl_numbers (numbers,cute) VALUES ('".addslashes($data[0])."','".addslashes($data[1])."')"); } } while ($data = fgetcsv($handle,1000,",","'")); echo "Successful Upload~!"; } ?&gt; </code></pre> <p>Thanks for the reply.</p>
    singulars
    1. This table or related slice is empty.
    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. 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