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();
});
}); 
Link to comment
https://forums.phpfreaks.com/topic/287501-php-ajax-file-not-uploading/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.