【发布时间】:2012-02-24 21:39:59
【问题描述】:
我正在尝试使用http://www.finalwebsites.com/snippets.php?id=7 提供的这个 PHP 类上传文件(查看http://pastebin.com/sqbMw4sR 类的代码)
我在上传处理文件中有以下代码
$max_size = 1024*100; // the max. size for uploading
$my_upload = new file_upload;
// upload directory
$my_upload->upload_dir = HOME_PATH."users/";
// allowed extensions
$my_upload->extensions = array(".png", ".jpeg", ".jpg", ".gif");
$my_upload->max_length_filename = 50;
$my_upload->rename_file = true;
$new_name = "testing" . time();
if(isset($Submit)) {
$my_upload->the_temp_file = $_FILES['upload']['tmp_name'];
$my_upload->the_file = $_FILES['upload']['name'];
$my_upload->http_error = $_FILES['upload']['error'];
$my_upload->the_mime_type = $_FILES['upload']['type'];
// because only a checked checkboxes is true
$r = $_POST['replace'];
$my_upload->replace = (isset($r)) ? $r : "n";
// use this boolean to check for a valid filename
$a = $_POST['check'];
$my_upload->do_filename_check = (isset($a)) ? $a : "n";
if ($my_upload->upload($new_name)) {
// new name is an additional filename information,
//use this to rename the uploaded file
$full_path = $my_upload->upload_dir.$my_upload->file_copy;
// just some information about the uploaded file
$info = $my_upload->get_uploaded_file_info($full_path);
// ... or do something like insert the filename to the database
}
}
$error = $my_upload->show_error_string();
据我了解,该文件应该已经上传,但既没有抛出任何错误,也没有上传。
我正在使用 ajaxForm(jquery 插件 http://malsup.com/jquery/form/#file-upload)调用此文件。
谁能指出这里有什么问题?
【问题讨论】:
-
你发布的数据,在这个类中接收,在你的 ajaxForm() 函数中用 alert 进行检查
-
我不知道该怎么做?在开发人员的 Web 控制台中,我可以看到正在执行 xhr 调用。
标签: php jquery ajax file-upload