Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The logic of the code you are posting is not correct.</p> <p>Initially when you want to upload a file , there were two logics :</p> <p>1- Use same php file for displaying the form and for processing the upload :</p> <p>Put the form layout that will contains the file field in a block , and the upload process in another block.</p> <p>I mean that you must split your code into 2 parts :</p> <ul> <li><p>the first part will be executed if the page is accessed for the first time , and in this case the page must display the form that will ask user about the file you want to upload</p></li> <li><p>The second part it will be executed if the page is accessed due a post back (The user access this page after pressing a submit button within a form that point to this page)</p></li> </ul> <p>and the code of the file [upload.php] must be look like this :</p> <pre><code>&lt;?php include('menu/menu.html'); if (!isset($_POST['submit'])) { ?&gt; &lt;div id="search"&gt; &lt;form action="upload.php" method="post" enctype="multipart/form-data"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="file" name="filename"/&gt;&lt;/td&gt; &lt;td align="right"&gt;&lt;input type="submit" name="submit" value="Descargar"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/div&gt; &lt;?php } else { ?&gt; &lt;div id="result"&gt; &lt;div id="nresult"&gt; &lt;?php if ($_FILES['filename']['type'] != "application/pdf") {echo "Error " . $_FILES['filename'] . ": el archivo no es pdf.&lt;br&gt;";} else {\\Procces your upload} } </code></pre> <p>2- The second logic is to put the form layout in a file and the upload process in another file and point the form in the first page to the second page look like this :</p> <p>Put in the file named [uploadlayout.php]</p> <pre><code>&lt;div id="search"&gt; &lt;form name="form1" method="post" action="uploadcode.php" enctype="multipart/form-data"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="file" name="filename"/&gt;&lt;/td&gt; &lt;td align="right"&gt;&lt;input type="submit" name="submit" value="Descargar"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>And in the file named [uploadecode.php]</p> <pre><code>&lt;?php if ($_FILES['filename']['type'] != "application/pdf") {echo "Error " . $_FILES['filename'] . ": el archivo no es pdf.";} else {//Proccess your upload} </code></pre> <p>?></p> <p>Now each time you access the page "uploadlayout.php" and you browse to a file then press the Submit button "Descragar" you will post the file choosen , to the "uploadcode.php" page and the test of the file type will be executed and if it succeed the upload process will be executed and if fail you will show the error "el archivo no es pdf"</p> <p>I hope that i have explained that clearly and if you have another question or just you need any clarification just let me know :)</p>
    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. 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