为什么通过PHP上传这个简单的图像是行不通的

时间:2016-05-22 17:15:47

标签: php forms file file-upload

您好我有3个小型多部分表格上传3张图片

这些是HTML部分(我有3次相同的代码):

<form method="post" action="?publishB&imageUploading1" enctype="multipart/form-data"><div class="fileUpload btn btn-primary"><span><strong>Cargar</strong></span><input type="file" name="imagen1" id="imagen1" class="uploadBotonGen" ></div><input type="submit" class="subirLaImagen" value="Publicar"></form>

这对我来说很好看!

PHP代码就是这个:

//                  IMAGEN 1

                    if(isset($_GET['imageUploading1']))
                    {


                                $imageName = addslashes($_FILE['imagen1']['name']);
                                $imageTempName =  $_FILE['imagen1']['tmp_name'];
                                $imageBlob = addslashes(file_get_contents($_FILE['imagen1']['tmp_name']) );
                                $imageSize = getimagesize($_FILE['imagen1']['size']) ;

                                if($imageSize==FALSE)
                                    {
                                        $errorFileType=$i;
                                        echo "a";
                                    }
                                    else
                                    {


                                         try                   
                                        {   
                                            $pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
                                            $bdd = new PDO('mysql:host=localhost;dbname=lacajota', 'root', '', $pdo_options);

                                            $req = $bdd->prepare('INSERT INTO imagenes(userID, articID, name, image) VALUES(:userID, :articID, :name, :image)');
                                            $req->execute(array(

                                            'userID'=> $_SESSION['userID'],
                                            'articID'=> $LastArtLast['ID'],
                                            'name'=> $imageName,
                                            'image'=> $imageBlob
                                             ));


                                        }
                                        catch(Exception $e)
                                        {   
                                            die('Error:' . $e->getMessage());
                                        }


                                    }           

                    }

服务器返回followinf错误:

注意:未定义的变量:第182行的C:\ wamp \ www \ La Cajota \ publish \ index.php中的_FILE

看起来我的PHP代码文件没有很好用!第一个错误出现在第一行($imageName = addslashes($_FILE['imagen1']['name']);

谢谢!

是的,这段代码重复3次,每个上传表格一个!

1 个答案:

答案 0 :(得分:1)

使用df2 <- read.table(text = "V1 V2 V3 V4 PC1 -0.5987139 -0.5987139 -0.03790446 0.5307039 PC2 -0.0189601 -0.0189601 -0.99315168 -0.1137136 PC3 0.3986891 0.3523926 -0.11045319 0.8394442", header = TRUE) m2 <- as.matrix(df2) d2 <- duplicated(m2, MARGIN = 0) | duplicated(m2, MARGIN = 0, fromLast = TRUE) colnames(m2)[unique(col(d2)[d2])] # [1] "V1" "V2"

$ _ FILE未定义

点击此链接http://php.net/manual/en/reserved.variables.files.php