PHP给出了;未定义索引“;图像文件上载错误|使用v类上载

PHP给出了;未定义索引“;图像文件上载错误|使用v类上载,php,file-upload,image-uploading,image-resizing,Php,File Upload,Image Uploading,Image Resizing,我正在使用php类上传 我想上传一个图像文件并调整它的大小。 但当我点击save按钮时出现了一些问题 注意:第47行C:\xampp\htdocs\projects\pakistanihaider\admin\profile.php中的未定义索引:profilepic 以下是我迄今为止所做的工作 HTML 我的表单标签: <form class="form-horizontal row-fluid" enctype="multipart/form-data" method="post"

我正在使用php类上传

我想上传一个图像文件并调整它的大小。 但当我点击save按钮时出现了一些问题

注意:第47行C:\xampp\htdocs\projects\pakistanihaider\admin\profile.php中的未定义索引:profilepic

以下是我迄今为止所做的工作

HTML 我的表单标签:

<form class="form-horizontal row-fluid" enctype="multipart/form-data" method="post" action="<?php $_PHP_SELF ?>">
第二,我使用了这个,因为我不知道他们为什么使用它,但他们在演示页面中使用了这个php

//Picture/File Upload Function
// retrieve eventual CLI parameters
$cli = (isset($argc) && $argc > 1);
if ($cli) {
    if (isset($argv[1])) $_GET['file'] = $argv[1];
    if (isset($argv[2])) $_GET['dir'] = $argv[2];
    if (isset($argv[3])) $_GET['pics'] = $argv[3];
}

// set variables
$dir_dest = (isset($_GET['dir']) ? $_GET['dir'] : '../userUploads/profile-pictures');
$dir_pics = (isset($_GET['pics']) ? $_GET['pics'] : $dir_dest);
现在,如果单击表单按钮,则显示主代码

if(isset($_POST['savebtn'])){

$full_name = $_POST['full_name'];
$job_title = $_POST['job_title'];
$email = $_POST['email'];
$dob = $_POST['dob'];
$mobile = $_POST['mobile'];
$phone = $_POST['phone'];
$nationality = $_POST['nationality'];
$profile_image = $_POST['profilepic'];
$address = mysql_real_escape_string($_POST['address']);
$about_me = mysql_real_escape_string($_POST['aboutme']);

$last_updated = date('F j, Y, g:i a');


// ---------- IMAGE UPLOAD ----------

    // we create an instance of the class, giving as argument the PHP object
    // corresponding to the file field from the form
    // All the uploads are accessible from the PHP object $_FILES
    $handle = new Upload($_FILES['profilepic']);

    // then we check if the file has been uploaded properly
    // in its *temporary* location in the server (often, it is /tmp)
    if ($handle->uploaded) {

        // yes, the file is on the server
        // below are some example settings which can be used if the uploaded file is an image.
        $handle->image_resize            = true;
        $handle->image_ratio_y           = true;
        $handle->image_x                 = 300;

        // now, we start the upload 'process'. That is, to copy the uploaded file
        // from its temporary location to the wanted location
        // It could be something like $handle->Process('/home/www/my_uploads/');
        $handle->Process($dir_dest);

        // we check if everything went OK
        if ($handle->processed) {
            // everything was fine !

            $uploadresult = '  <b>File uploaded with success</b><br />';
            $uploadresult .= '  <img src="'.$dir_pics.'/' . $handle->file_dst_name . '" />';
            $info = getimagesize($handle->file_dst_pathname);
            $uploadresult .= '  File: <a href="'.$dir_pics.'/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a><br/>';
            $uploadresult .= '   (' . $info['mime'] . ' - ' . $info[0] . ' x ' . $info[1] .' -  ' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB)';

        } else {
            // one error occured

          $uploadresult = '  <b>File not uploaded to the wanted location</b><br />';
          $uploadresult .= '  Error: ' . $handle->error . '';

        }

        // we now process the image a second time, with some other settings
        $handle->image_resize            = true;
        $handle->image_ratio_y           = true;
        $handle->image_x                 = 300;
        $handle->image_reflection_height = '25%';
        $handle->image_contrast          = 50;

        $handle->Process($dir_dest);

        // we check if everything went OK
        if ($handle->processed) {
            // everything was fine !

            $uploadresult2 = '  <b>File uploaded with success</b><br />';
            $uploadresult2 .= '  <img src="'.$dir_pics.'/' . $handle->file_dst_name . '" />';
            $info = getimagesize($handle->file_dst_pathname);
            $uploadresult2 .= '  File: <a href="'.$dir_pics.'/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a><br/>';
            $uploadresult2 .= '   (' . $info['mime'] . ' - ' . $info[0] . ' x ' . $info[1] .' - ' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB)';

        } else {
            // one error occured

            $uploadresult2 = '  <b>File not uploaded to the wanted location</b><br />';
            $uploadresult2 .= '  Error: ' . $handle->error . '';

        }

        // we delete the temporary files
        $handle-> Clean();

    } else {
        // if we're here, the upload file failed for some reasons
        // i.e. the server didn't receive the file

        $failedupload = '  <b>File not uploaded on the server</b><br />';
        $failedupload .= '  Error: ' . $handle->error . '';

            }






$success = update_profile($full_name, $dob, $nationality, $address, $mobile, $phone, $job_title, $about_me, $profile_image, $last_updated, $email);



}
if(isset($\u POST['savebtn'])){
$full_name=$_POST['full_name'];
$job_title=$_POST['job_title'];
$email=$_POST['email'];
$dob=$_POST['dob'];
$mobile=$_POST['mobile'];
$phone=$_POST['phone'];
$国籍=$_职位['国籍'];
$profile_image=$\u POST['profilepic'];
$address=mysql\u real\u escape\u字符串($\u POST['address']);
$about_me=mysql_real_escape_字符串($_POST['aboutme']);
$last_updated=日期('fj,Y,g:ia');
//------图片上传----------
//我们创建该类的一个实例,将PHP对象作为参数
//对应于表单中的文件字段
//所有上传都可以从PHP对象$\u文件访问
$handle=新上载($_文件['profilepic']);
//然后我们检查文件是否已正确上传
//在服务器中的*临时*位置(通常是/tmp)
如果($handle->上传){
//是的,文件在服务器上
//下面是一些示例设置,如果上载的文件是图像,则可以使用这些设置。
$handle->image\u resize=true;
$handle->image\u ratio\u y=true;
$handle->image_x=300;
//现在,我们开始上传“过程”,即复制上传的文件
//从其临时位置到所需位置
//它可能类似于$handle->Process('/home/www/my_uploads/');
$handle->Process($dir\u dest);
//我们检查一切是否正常
如果($handle->processed){
//一切都很好!
$uploadresult='File upload with success
'; $uploadresult.=“文件名”。“/>”; $info=getimagesize($handle->file_dst_pathname); $uploadresult.=“文件:
”; $uploadresult.='('.$info['mime'].-'.$info[0].'x'.$info[1].-'.round(文件大小($handle->file_dst_pathname)/256)/4.KB); }否则{ //发生了一个错误 $uploadresult='文件未上载到所需位置
'; $uploadresult.='Error:'.$handle->Error'; } //现在,我们使用一些其他设置再次处理图像 $handle->image\u resize=true; $handle->image\u ratio\u y=true; $handle->image_x=300; $handle->image_reflection_height='25%'; $handle->image\u对比度=50; $handle->Process($dir\u dest); //我们检查一切是否正常 如果($handle->processed){ //一切都很好! $uploadresult2='File upload with success
'; $uploadresult2.=“文件名”。“/>”; $info=getimagesize($handle->file_dst_pathname); $uploadresult2.=“文件:
”; $uploadresult2.='('.$info['mime'].-'.$info[0].'x'.$info[1].-'.round(文件大小($handle->file_-dst_-pathname)/256)/4.KB); }否则{ //发生了一个错误 $uploadresult2='文件未上载到所需位置
'; $uploadresult2.='错误:'.$handle->错误'; } //我们删除临时文件 $handle->Clean(); }否则{ //如果我们在这里,由于某些原因上载文件失败 //也就是说,服务器没有收到该文件 $failedupload='文件未上载到服务器上
'; $failedupload.='Error:'.$handle->Error'; } $success=更新个人资料($full_name、$dob、$national、$address、$mobile、$phone、$job_title、$about_me、$profile_image、$last_updated、$email); }
我现在没有使用image来更新数据库,这就是为什么我没有在
update\u profile
函数中使用image变量的原因

现在的问题是,每当我单击“保存”按钮时,我都会得到
未定义的索引


如何解决此问题?

只需删除此行即可

$profile_image = $_POST['profilepic'];
在主代码中


文件是在_FILES数组中发送的,因此它不是在_POST中设置的,您会收到通知。

只需删除这一行即可

$profile_image = $_POST['profilepic'];
在主代码中


文件是在_FILES数组中发送的,因此它不是在_POST中设置的,您会收到通知。

您需要使用
isset()
查看表单元素是否已填写

未定义索引
说明您正在访问一个不存在的数组项。例如:

$arr = array('a' => 'x', 'b' => 'y');
$c = $arr['c'];
// Notice: Undefined index...
为了避免该通知,您需要先检查它是否存在:

if (isset($arr['c'])) {
    $c = $arr['c'];
} else {
    $c = FALSE;
}

您需要使用
isset()
来确定表单元素是否已填写

未定义索引
说明您正在访问一个不存在的数组项。例如:

$arr = array('a' => 'x', 'b' => 'y');
$c = $arr['c'];
// Notice: Undefined index...
为了避免该通知,您需要先检查它是否存在:

if (isset($arr['c'])) {
    $c = $arr['c'];
} else {
    $c = FALSE;
}

很好,但是如果我没有从$\u POST获取路径,如何在数据库中存储图像的路径?很好,但是如果我没有从$\u POST获取路径,如何在数据库中存储图像的路径??