English 中文(简体)
图像上的有效载荷在以前的中子上载在PHP
原标题:Image upload takes previous temp file to upload in PHP

在此,我有在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.

问题是什么以及如何解决?

$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..!";
        }

此处,<代码>response是用来取得地位的变量。

最佳回答

Sounds like you are using some sort of AJAX to call this function.

您也许需要找到一种办法,在这项职能结束时重新确定“FranLES”阵列。

$_FILES = array();

否则,由于在文件上载后没有(表面)一页复读(如你提到的那样),我认为,“FLE”变量不可能自然地重新出现(如你在此使用AJAX公司时会发生)。

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签