上载和显示错误路径名时报告的错误

时间:2015-06-23 05:52:02

标签: php html

我有一个上传两张图片的表单,并在DB中保存它们的路径。

if (isset($_POST['add_artimage'])) {
    if ($_FILES["front"]) {
        upload_file("front");
    }
    if ($_FILES["back"]) {
        upload_file("back");
    }
    $front = upload_file($front);
    $back = upload_file($back);
    echo "image_front is $front <br> image_back is $back";
}

function upload_file($name) {
    $folder = "prod-images/";
    $folder2 = "users/";
    $open_type_upload = ".jpg";

    $file_name = $_FILES[$name]['name'];
    $file_tmp = $_FILES[$name]['tmp_name'];
    $file_size = $_FILES[$name]['tmp_size'];
    $file_type = $_FILES[$name]['type'];
    $rand_file_name = rand(1000000000, 9999999999999);

    $newfile_name = $rand_file_name.$file_name;
    $open_types = array(
        "image/jpg",
        "image/jpeg",
        "image/png",
        "image/gif");
    $upload = move_uploaded_file($file_tmp, $folder.$rand_file_name.$open_type_upload);
    echo "ok";
    $image = "$folder2$folder$rand_file_name$open_type_upload";
    return $image;
}

这是我的HTML

<td>image_front:</td>
<td><input name='front' type='file' id='ufile'  /></td>
</tr>
<tr>
<td>image_back:</td>
<td><input name='back' type='file' id='ufile'  /></td>

当我尝试上传时,会将文件上传到目录,但也会报告以下错误:

  

注意:未定义的变量:前面

     

注意:未定义的变量:返回

     

注意:未定义的变量:index

echo image_frontimage_back的路径时,echo与上传的目录中的真实名称不同。

1 个答案:

答案 0 :(得分:0)

1def self.assign_common_variables # your logic end def self.set_vendor # your business logic end def self.update_product_actions # business logic end controller.rb def your_action # you can call the method you wrote in your model here like below. @variable = @variable.assign_common_variables end def your_another_action # you can call the method you wrote in your model here like below. @vendor = Vendor.set_vendor end 未定义,您应该考虑以下因素:

$front