0

我的表单中有一个上传字段。

我的 form.php 中有这段代码

<form id="photoform" name="photoform" method="post" onSubmit="return false" enctype="multipart/form-data">
                  <div id="upphotosection"></div>
                   <label>Upload photo</label>
                   <input name="uploadphoto" id="uploadphoto" type="file" />
                   <div class="innerformclear"></div>
                   <input id="hidden" value="" name="hidden" type="hidden" />
                   <label>&nbsp;</label>
                   <input name="upphoto_submit" id="upphoto_submit" type="submit" value="Submit"/>
                    <div style="clear:both;">&nbsp;</div>
                   <label>&nbsp;</label>
                   <div id="result_upphoto_submit"></div>
                   </form>

这是formaction.php中的代码

header('content-type: application/json; charset=utf-8');
header("access-control-allow-origin: *");

include("../../../wp-load.php");
session_start();

    $err = '';
    $success = '';
    global $wpdb, $PasswordHash, $current_user, $user_ID;

    if($upphoto = $_FILES['uploadphoto']["name"] != '' ){
    $path = 'images/profilephotos/';    
    $upphoto = copyServiceImage($path,$_FILES['uploadphoto']) ;}

    $postid = 52;


############### Check Duplication
$sel_photo = "SELECT * FROM `pro_table` WHERE `post_id` = '".$postid."'";
$sel_res = mysql_query($sel_photo) ;
if(mysql_num_rows($sel_res) == 0){
$ins_photo = "Insert into pro_table (post_id,photo_photo,int_status) values ('$postid','$upphoto','0')";
$ins_res = mysql_query($ins_photo);
}
else{
$upd_photo = "Update pro_table set photo_photo = '$upphoto' ,int_status='0' where  post_id = '$postid' ";
$upd_res = mysql_query($upd_photo);
}


echo $_GET['callback'] . '('.json_encode("success").')';

这是java脚本文件中的代码。

$(document).ready(function() {  
///////////// Submit action for upload photo        
    $("#upphoto_submit").click(function() {

        if(document.getElementById('uploadphoto').value == '' ){
            alert("Please upload Photo");
            document.getElementById('uploadphoto').focus();
            return false;
        }
        else {
            $('#result_upphoto_submit').html('<img src="http://www.test.com/test/uploads/2012/04/ajax-loader.gif" class="loader" align="absmiddle" />&nbsp;').fadeIn(); 
                var input_data = $('#photoform').serialize();
                $.ajax({
                type: "POST",
                url:  "http://www.test.com/test/themes/test/formaction.php",
                dataType: 'jsonp',
                data: input_data,
                success: function(msg){
                    $('#result_upphoto_submit').html('&nbsp;');
                    if(msg == 'success') {
                        msg = '<p class="success_custom">Photo successfully added.</p>';
                        $('<div>').html(msg).appendTo('div#upphotosection').hide().fadeIn('slow');
                    } else {

                        msg = ' Exists';
                        alert("Error in updation");

                    }

                }
                });
                return false;
        }       

        }); 
});

如果我浏览图像并单击提交,它会向我显示成功消息Photo successfully added。但是个人资料照片文件夹中没有图像,并且管理面板中没有存储数据。我无法追踪错误。我该如何纠正?

4

1 回答 1

0

有错误吗?

$_FILES["uploadphoto"]["error"];

我也不知道 wordpress 如何处理图像,但我想念文件移动:

if ($_FILES["uploadphoto"]["error"] != UPLOAD_ERR_OK) {
   $tmp_name = $_FILES["uploadphoto"]["tmp_name"];
   $name = $_FILES["pictures"]["name"];
   $path = "images/profilephotos/".$name;
   move_uploaded_file($tmp_name,$path);
}

或者我想它在这里被调用?

$upphoto = copyServiceImage($path,$_FILES['uploadphoto']) ;}
于 2012-05-28T12:28:54.880 回答