【问题标题】:Help With Renaming Files With Uploadify帮助使用 Uploadify 重命名文件
【发布时间】:2011-07-03 14:41:35
【问题描述】:

这是我的代码 -

<?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.';
    // }
}

?>

为什么上述方法不起作用?如您所见,我试图从用户数据库中提取名称,然后将上传的文件重命名为从数据库中提取的名称。

你能帮帮我吗?非常感谢。

【问题讨论】:

  • 哪个部分不工作?是否正在生成错误?文件是实际上传的还是空的?
  • 文件未上传。错误 HTTP_ERROR。
  • 请复制准确的错误信息。
  • 确保您的表单具有正确的 enctype (multipart/form-data)

标签: php database file upload


【解决方案1】:

form enctype == 'multipart/form-data' 吗?

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2010-12-13
      • 1970-01-01
      • 1970-01-01
      • 2011-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-17
      • 2011-01-27
      相关资源
      最近更新 更多