ArshSingh Posted April 3, 2014 Share Posted April 3, 2014 (edited) so i have the following code and i can't figure out what the problem is , its not uploading the image , jquery works but don't know whats going on with php i have done all the possible things , working on codes from morning , so maybe missed something in this code due to my head want some rest , a help will good : php <?php include"functions.php"; $username =$session->username; $path = "../images/"; $valid_formats = array("jpg", "png", "gif", "bmp","jpeg"); 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<(1024*1024)) // Image size max 1 MB { $actual_image_name = time().$username.".".$ext; $tmp = $_FILES['photoimg']['tmp_name']; if(move_uploaded_file($tmp, $path.$actual_image_name)) { mysqli_query($GLOBALS["___mysqli_ston"], "UPDATE `users` SET `profilepic`='$actual_image_name' WHERE `username`='$username'"); echo "<img src='../images/".$actual_image_name."' class='preview'>"; } else echo "failed"; } else echo "Image file size max 1 MB"; } else echo "Invalid file format.."; } else echo "Please select image..!"; exit; } ?> jquery $(document).ready(function() { $('#photoimg').live('change', function() { $("#profilepic-big").html(''); $("#profilepic-big").html('<img src="images/loading.gif" alt="Uploading...."/>'); $("#imageform").ajaxForm( { target: '#profilepic-big'} ).submit(); }); }); Edited April 3, 2014 by ArshSingh Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 3, 2014 Share Posted April 3, 2014 Are you able to upload the image without using ajax? Quote Link to comment Share on other sites More sharing options...
ArshSingh Posted April 3, 2014 Author Share Posted April 3, 2014 No ,,, i have tried in different ways but no success Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 3, 2014 Share Posted April 3, 2014 Then, you need to fix first the server side scripting before to proceed to javascript/ajax. Quote Link to comment Share on other sites More sharing options...
ArshSingh Posted April 3, 2014 Author Share Posted April 3, 2014 (edited) Im trying but don't know whats wrong Edited April 3, 2014 by ArshSingh Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 3, 2014 Share Posted April 3, 2014 at a starting point turn on error reporting functions. Quote Link to comment Share on other sites More sharing options...
ArshSingh Posted April 3, 2014 Author Share Posted April 3, 2014 can u please check if the mysqli_query is okay? Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 3, 2014 Share Posted April 3, 2014 You should tell me, I'm not a magic What I want from you is just to provide us all errors coming from your script, then we'll be able to help you effectively. Quote Link to comment Share on other sites More sharing options...
ArshSingh Posted April 3, 2014 Author Share Posted April 3, 2014 Okay ,,, i think the error is before mysqli_query ,,, have to check it carefullg Quote Link to comment Share on other sites More sharing options...
jazzman1 Posted April 3, 2014 Share Posted April 3, 2014 When you go to the doctor or to a hospital, is it important you understand what they say to you? Quote Link to comment Share on other sites More sharing options...
ArshSingh Posted April 4, 2014 Author Share Posted April 4, 2014 Yup thats right Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.