Note that there are some explanatory texts on larger screens.

plurals
  1. POChecking file props before upload
    primarykey
    data
    text
    <p>I am practicing with PHP and AJAX but I have some problems!</p> <p>I'm trying to get the filename, type, size from a jQuery alert after select an image to upload, but I keep getting an empty string.</p> <pre><code>&lt;form action="upload_file.php" method="post" enctype="multipart/form-data"&gt; &lt;label for="file"&gt;Filename:&lt;/label&gt; &lt;input type="file" name="my_file" /&gt; &lt;input type="submit" name="submit" value="Submit" /&gt; &lt;/form&gt; </code></pre> <p>This form includes a <strong>JS</strong> file that has an ajax script that asks to a php page the filename of the posted file, but it doesn't work. Do I need to upload the file before I try to get this data?</p> <p>The JS file:</p> <pre><code>$("input").change (function () { $.post("preview_uploader.php", { action:"get_size" }, function (data) { alert (data); }); }); </code></pre> <p>The PHP file <strong>preview_uploader.php</strong>:</p> <pre><code>&lt;?php if ($_POST["action"] == "get_test") print "text string test works!"; if ($_POST["action"] == "get_name") print $_FILES["my_file"]["name"]; if ($_POST["action"] == "get_size") print $_FILES["my_file"]["size"]; if ($_POST["action"] == "get_type") print $_FILES["my_file"]["type"]; ?&gt; </code></pre> <p>It works if i make a test with <code>action:"get_test"</code> with php page but it doesn't work with <code>$_FILES["my_file"]["name"]</code> or <code>$_FILES["my_file"]["type"]</code> etc...</p> <p>Can someone help me find where I am wrong?</p> <p>Thanks!</p>
    singulars
    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.
 

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