简体   繁体   English

帮助使用Uploadify重命名文件

[英]Help With Renaming Files With Uploadify

This is my code - 这是我的代码-

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

?> ?>

Why is the above not working? 为什么上述方法不起作用? As you can see, I am trying to pull down the name from the users database, and then rename the uploaded file to the name that was pulled from the db. 如您所见,我试图从用户数据库中提取名称,然后将上载的文件重命名为从数据库中提取的名称。

Can you help me out? 你能帮我吗? Thanks a lot. 非常感谢。

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

Ah, now I understand what you're talking about. 啊,现在我明白了您在说什么。 You should remove your other post. 您应该删除其他帖子。 This is an error I've actually encountered with Uploadify before, but I'm not sure what is going on here, specifically. 这是我以前在Uploadify上实际遇到的一个错误,但是我不确定这里到底发生了什么。 Definitely, checkout your enctype, but for debugging, I implemented this solution for error reporting with Uploadify here: http://www.uploadify.com/forums/discussion/14/upload-script-error-reporting/p1 . 肯定地,请检查您的enctype,但是为了进行调试,我在此处通过Uploadify实现了该解决方案,用于错误报告: http ://www.uploadify.com/forums/discussion/14/upload-script-error-reporting/p1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM