帮助使用Uploadify重命名文件

时间:2011-02-24 14:19:04

标签: php database file upload

这是我的代码 -

<?php
session_start();
include('connect.php');
mysqli_select_db($connect, "users");
$s = "select * from name where sessionusername = '$u'";
$q = mysqli_query($connect, $s);
$f = mysqli_fetch_array($q);
$name = $f['name'];

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

    // $fileTypes  = str_replace('*.','',$_REQUEST['fileext']);
    // $fileTypes  = str_replace(';','|',$fileTypes);
    // $typesArray = split('\|',$fileTypes);
    // $fileParts  = pathinfo($_FILES['Filedata']['name']);

    // if (in_array($fileParts['extension'],$typesArray)) {
        // Uncomment the following line if you want to make the directory if it doesn't exist
        // mkdir(str_replace('//','/',$targetPath), 0755, true);
        // Get the extension, and build the file name
     //$extension = pathinfo($tempFile, PATHINFO_EXTENSION); 
     $extension = end(explode(".",$_FILES['Filedata']["name"])); 
     $new_file_name =  '".$name."'".".$extension;

    $targetFile =  str_replace('//','/',$targetPath) . $new_file_name;
    // $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];




        move_uploaded_file($tempFile,$targetFile);
        echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
    // } else {
    //  echo 'Invalid file type.';
    // }
}

&GT;

为什么以上不起作用?如您所见,我试图从用户数据库中删除该名称,然后将上载的文件重命名为从db中提取的名称。

你能救我吗?非常感谢。

2 个答案:

答案 0 :(得分:1)

表单是enctype =='multipart / form-data'?

答案 1 :(得分:0)

啊,现在我明白你在说什么了。你应该删除你的其他帖子。这是我之前遇到过的一个错误,但是我不确定这里发生了什么。当然,请检查您的enctype,但为了进行调试,我在此处使用Uploadify实现了此错误报告解决方案:http://www.uploadify.com/forums/discussion/14/upload-script-error-reporting/p1