gpt4 book ai didi

php - 如何使用 uploadify 传递表单值

转载 作者:行者123 更新时间:2023-11-28 10:14:51 27 4
gpt4 key购买 nike

    jQuery(document).ready(function() {
jQuery("#file_upload").uploadify({
'uploader' : '/wp-content/plugins/amazon-s3-simple-upload-form/files/uploadify/uploadify.swf',
'script' : '/wp-content/plugins/amazon-s3-simple-upload-form/files/uploadify/uploadify.php',
'folder' : '/uploads',
'auto' : true,
'buttonText' : 'Browse',
'cancelImg' : '/wp-content/plugins/amazon-s3-simple-upload-form/files/uploadify/cancel.png',
'fileExt' : '*.*',
'fileDataName' : 'file_upload',
'simUploadLimit': 2,
'multi' : true,
'auto' : true,
'onError' : function(event, ID, fileObj, errorObj) {alert(errorObj.type+"::"+errorObj.info);
},
'onComplete' : function(event, ID, file, response, data) { console.log(file);}
});
});

那是我的 JS 文件....

<?php
/*
Uploadify v2.1.4
Release Date: November 8, 2010

Copyright (c) 2010 Ronnie Garcia, Travis Nickels

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
include_once($_SERVER['DOCUMENT_ROOT'].'/wp-config.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
include_once($_SERVER['DOCUMENT_ROOT'].'/wp-includes/wp-db.php');


error_reporting(E_ALL);
ini_set("display_errors", 1);

if (!empty($_FILES)) {

$tempFile = $_FILES['file_upload']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['file_upload']['name'];
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions

global $current_user;
$current_user = wp_get_current_user();
$userid = $current_user->ID;
$username = $current_user->user_login;
$email = $current_user->user_email;
$first_name = $current_user->user_firstname;
$last_name = $current_user->user_lastname;
$upload_time = date( 'Y-m-d H:i:s', time());
$upload_url = $targetFile;
$s3userIP = $_SERVER["REMOTE_ADDR"];
$description = $_POST['filedesc'];

if (move_uploaded_file($tempFile,$targetFile))
{
$insertuser = mysql_query("INSERT INTO wp_110504s3userDBinfo( upload_time, user_name, email_add, description, upload_url,s3_userIP) values ('$upload_time','".$username."', '".$email."', '".$description."', '".$upload_url."', '".$s3userIP."')") or die(mysql_error());
}

}
?>

那就是Uploadfiy.php网址是Uploadify URL is

实际上我正在使用 worpress cms,我希望将其导入到 wordpress,请检查有什么问题

最佳答案

问题出在您的 uploadify.php 脚本中。您必须将输入文件名修改为 Filedata 或者必须在 uploadify.php $_FILES['Filedata'] 中修改与 $_FILES['file_upload']

if (!empty($_FILES)) {
$tempFile = $_FILES['file_upload']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['file_upload']['name'];
move_uploaded_file($tempFile,$targetFile);
echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);

}

(file_upload 是您的 <input type='file' id='file_upload' name='file_upload' /> )

编辑:

您必须将其添加到您的脚本中:

'onSelect'      : function(event,ID,fileObj) {

$('#file_upload').uploadifySettings('scriptData',{filedesc:$('#filedesc').val()});

}

像这样:

jQuery("#file_upload").uploadify({
'uploader' : 'uploadify.swf',
'script' : 'uploadify.php',
'folder' : '/wp-content/uploads',
'auto' : true,
'buttonText' : 'Browse',
'cancelImg' : 'cancel.png',
'fileExt' : '*.*',
'fileDataName' : 'file_upload',
'simUploadLimit' : 2,
'multi' : true,
'auto' : true,
'method' : 'post',
'onComplete' : function(event, ID, file, response, data) {},

'onSelect' : function(event,ID,fileObj) {

$('#file_upload').uploadifySettings('scriptData',{filedesc:$('#filedesc').val()});

}

});

您的问题是您在 init 上设置 scriptData,而当时您的描述为空。所以我更新了 select 事件的 scriptData 值

你得到错误但你无法读取它们,所以将它们放入txt文件中。将其放入 uploadify.php 中此行之后

$insertuser = mysql_query("INSERT INTO wp_110504s3userDBinfo( upload_time, user_name, email_add, description, upload_url,s3_userIP) values  ('$upload_time','".$username."', '".$email."', '".$description."', '".$upload_url."', '".$s3userIP."')") or die(mysql_error());

$flname= "testFile.txt";
$flHandle= fopen($flname, 'w') or die("can't open file");
$wr = fwrite($flHandle,mysql_errors());
fclose($ourFileHandle);

如果您在服务器上运行此程序(而不是 Windows 上的本地主机),则必须设置权限

对于这个脚本。之后打开txt文件并读取错误。如果您想确保 php 正确接收参数,您可以使用发送的描述名称创建一个目录。

在uploadify中:mkdir($_POST['filedesc']);

关于php - 如何使用 uploadify 传递表单值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6799429/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com