Jump to content

PHP AJAX FILE NOT UPLOADING


ArshSingh

Recommended Posts

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 by ArshSingh
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.