Skip to main content

Image upload takes previous temp file to upload in php



Here i have the problem with uploading image in php.





The problem is that when first time i upload the image file it works fine. But when i am trying to upload the file second time without page refresh it takes first image name and upload it.





Anybody can tell me what the problem and how can it resolve ?







$name = $_FILES['ImageFile']['name'];

$size = $_FILES['ImageFile']['size'];

$tmp = $_FILES['ImageFile']['tmp_name'];



$path = "public/www/uploads/";

$valid_formats = array("jpg", "png", "gif", "bmp");

$response = '';

if(strlen($name)) {



list($txt, $ext) = explode(".", $name);

if(in_array($ext,$valid_formats)) {



if($size<(1024*1024)) {



$actual_image_name = time().substr(str_replace(" ", "_", $txt), 5).".".$ext;

if(move_uploaded_file($tmp, $path.$actual_image_name)) {



$response = "<img src='public/www/uploads/".$actual_image_name."?parm=".time()."' class='preview'>";



} else {

$response = "failed";

}

} else {

$response = "Image file size max 1 MB";

}

} else {

$response = "Invalid file format..";

}

} else {

$response = "Please select image..!";

}







here response is a variable that used to get status.


Comments

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?