Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<pre><code>Here is the code Jquery + PHP [Cake PHP] View file upload.ctp &lt;script type="text/javascript" src="http://demos.9lessons.info/ajaximageupload/scripts/jquery.form.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; $(document).ready(function(){ $('#photoimg').on('change', function(){ $("#preview").html(''); $("#preview").html('&lt;img src="/images/ajax-loader.gif" alt="Uploading...."/&gt;'); $("#imageform").ajaxForm({target: '#preview',success: showResponse}).submit(); }); }); &lt;/script&gt; &lt;form id="imageform" method="post" enctype="multipart/form-data" action='/media/upload'&gt; Upload image &lt;input type="file" name="photoimg" id="photoimg" /&gt; &lt;/form&gt; &lt;div id='preview'&gt;&lt;/div&gt; create a function with name upload in Media controller function upload(){ $this-&gt;layout = ''; $session_id='1'; // User session id $path = "images/media/images/original/"; $valid_formats = array("jpg", "png", "gif", "bmp","jpeg"); if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){ //pr($_FILES);die; //if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){ $name = $_FILES['photoimg']['name']; $size = $_FILES['photoimg']['size']; if(strlen($name)) { list($txt, $ext) = explode(".", $name); if(in_array($ext,$valid_formats)){ if($size&lt;(1024*1024)) { // Image size max 1 MB $txt=str_replace(" ","_",$txt); $actual_image_name = $txt."_".time().".".$ext; $tmp = $_FILES['photoimg']['tmp_name']; App::import('Vendor', 'resize'); if(move_uploaded_file($tmp, $path.$actual_image_name)) { //Code for image resize //mysql_query("UPDATE users SET profile_image='$actual_image_name' WHERE uid='$session_id'"); // save this to DB into Temp Selection table set USer wise and Capsule or individual Board wise echo "&lt;img src='/images/media/images/".$actual_image_name."' class='preview'&gt;&lt;br/&gt;&lt;a href='javascript:void(0);' id='upload_submit'&gt;Submit&lt;/a&gt;"; } else echo "failed"; } else echo "Image file size max 1 MB"; } else echo "Invalid file fo`enter code here`rmat.."; } else echo "Please select image..!"; exit; } } </code></pre>
 

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