Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularjs - File upload with php
    primarykey
    data
    text
    <p>I have spent days looking for a fairly simple integration of angularjs file upload method that includes a basic php server side script..</p> <p>I need a simple form one field and file upload upload. </p> <p>All examples I find are either heavily relying of jQuery or if they seem like something I could use their "examples" are completely unclear and messy.</p> <p>These two examples (if I could figure out how to incorporate with PHP) would solve my puzzle..</p> <p>Example 5 on this page <a href="http://ng-upload.eu01.aws.af.cm/" rel="noreferrer">http://ng-upload.eu01.aws.af.cm/</a> </p> <p>And the example on this page is one I really like a lot.. <a href="http://angular-file-upload.appspot.com/" rel="noreferrer">http://angular-file-upload.appspot.com/</a></p> <p>Could someone bring more light into this for me.. I would really like to see a one input filed and one file upload with as simple as possible angular and php code if such thing exists somewhere.</p> <p>I would be happy to implement this <a href="http://twilson63.github.io/ngUpload/" rel="noreferrer">http://twilson63.github.io/ngUpload/</a> or <a href="http://angular-file-upload.appspot.com/" rel="noreferrer">http://angular-file-upload.appspot.com/</a></p> <p>If this is my PHP</p> <pre><code>$fname = $_POST["fname"]; if(isset($_FILES['image'])){ $errors= array(); $file_name = $_FILES['image']['name']; $file_size =$_FILES['image']['size']; $file_tmp =$_FILES['image']['tmp_name']; $file_type=$_FILES['image']['type']; $file_ext = strtolower(pathinfo($file_name, PATHINFO_EXTENSION)); $extensions = array("jpeg","jpg","png"); if(in_array($file_ext,$extensions )=== false){ $errors[]="image extension not allowed, please choose a JPEG or PNG file."; } if($file_size &gt; 2097152){ $errors[]='File size cannot exceed 2 MB'; } if(empty($errors)==true){ move_uploaded_file($file_tmp,"images/".$file_name); echo $fname . " uploaded file: " . "images/" . $file_name; }else{ print_r($errors); } } ?&gt; </code></pre> <p>and this my basic html</p> <pre><code>&lt;form action="" method="POST" enctype="multipart/form-data"&gt; &lt;input type="text" name="fname" /&gt; &lt;input type="file" name="image" /&gt; &lt;input type="submit"/&gt; &lt;/form&gt; </code></pre> <p>How could I approach this (cleanly)? What should my controller and adjusted html look like? </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