简体   繁体   English

PHP文件无法正确通过Wordpress变量

[英]PHP file won't pass Wordpress Variable Properly

Have a really weird problem and can't figure out. 有一个很奇怪的问题,无法解决。 I'm using 'UPLOADIFY' to upload images from a small web app. 我正在使用“ UPLOADIFY”从小型网络应用上传图片。 It was working perfectly for months, then all of a sudden stopped working. 它运行了好几个月,然后突然停止工作。 Ideally I want to grab the logged in Wordpress user's username and add it to the image filename. 理想情况下,我想获取登录的Wordpress用户的用户名并将其添加到图像文件名。

Here is part of my uploadify file: 这是我的uploadify文件的一部分:

<?php
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');
global $user_login , $user_email;
      get_currentuserinfo();

$variableuser_id = $user_login;
$ses_id = $variableuser_id;
$ses_id = "1" . $ses_id . "z";
echo "This is a test " . $ses_id;

Then later in uploadify I have: 然后稍后在uploadify中,我有:

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
    $targetFile = rtrim($targetPath,'/') . '/' . $ses_id . "-" . str_replace(" ", "", $_FILES['Filedata']['name']);

So...when I upload an image using uploadify it will not add the username into the image name, it does ad the "1" and the "z" to the file name but is totally missing the username in the middle. 所以...当我使用uploadify上传图像时,它不会在图像名称中添加用户名,它确实在文件名中添加了“ 1”和“ z”,但中间完全没有用户名。

If I launch the uploadify.php file regular in my browser it will display "This is a test 1adminz" as it should for being logged in as admin. 如果我在浏览器中正常启动uploadify.php文件,它将显示“ This is a test 1adminz”,因为它应该以admin身份登录。 Any ideas? 有任何想法吗? I'm stumped! 我很沮丧! BTW I know $ses_id isn't ideal varname but it was just carrying over in my code from when I had a session ID named that. 顺便说一句,我知道$ ses_id不是理想的varname,但是它只是在我有一个名为session的会话ID时才在我的代码中继续使用。

Instead of 代替

global $user_login , $user_email;
      get_currentuserinfo();

Use 采用

global $current_user;
get_currentuserinfo()
$user_login = $current_user->user_login;
$user_email = $current_user->user_email;

For reference, see http://codex.wordpress.org/Function_Reference/get_currentuserinfo 有关参考,请参见http://codex.wordpress.org/Function_Reference/get_currentuserinfo

Ok I really can't explain this but I found a solution that fixed uploadify on each of my installs on a few different servers. 好的,我真的无法解释这一点,但是我找到了一个解决方案,该解决方案在几个不同服务器上的每个安装中修复了uploadify。

Took this line 走这条线

$targetFile = rtrim($targetPath,'/') . '/' . $ses_id . "-" . str_replace(" ", "", $_FILES['Filedata']['name']);

Then commented half of it out 然后注释掉一半

$targetFile = rtrim($targetPath,'/') . '/' . $ses_id . "-"; // . str_replace(" ", "", $_FILES['Filedata']['name']);

Surprise suprise, it renames an uploaded image now with the $ses_id variable combined with '-'. 令人惊讶的是,它现在使用$ ses_id变量和'-'重命名了上传的图像。 No image suffix obviously. 没有明显的图像后缀。

So for the hell of it, I uncommented out that ending part, and low and behold IT WORKS! 所以对于它的地狱,我没有评论结尾部分,并且低估了它的工作! MIND BLOWN! 心灵飞扬!

This makes no sense to me but solved on multiple servers! 这对我来说没有任何意义,但可以在多台服务器上解决!

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

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