[英]Can't move/fine APC Uploaded file
As a bit of a follow up to Javascript form won't submit (to view the code I am using visit that link) I am now encountering a problem that I cannot find the file that has been uploaded. 作为对Javascript表单的后续跟踪, 将不会提交 (要查看我正在使用的代码,请访问该链接),我现在遇到一个问题,我找不到已上传的文件。
I have added $files = apc_fetch('files_'.$_POST['APC_UPLOAD_PROGRESS']);
我添加了
$files = apc_fetch('files_'.$_POST['APC_UPLOAD_PROGRESS']);
to the top of my page and this is the output of print_r($files);
到我页面的顶部,这是
print_r($files);
的输出print_r($files);
Array
(
[theFile] => Array
(
[name] => tt1.mp4
[type] => video/mp4
[tmp_name] => /tmp/php2BEvy7
[error] => 0
[size] => 1050290
)
)
However when I try to run the following code: 但是,当我尝试运行以下代码时:
if (file_exists($files['theFile']['tmp_name'])) {
$webinarType = strcmp($files['theFile']['type'], 'video/mp4');
if($webinarType == 0) {
$webinarFile = $fileTitle;
$webinarTempName = $files['theFile']['tmp_name'];
} else {
echo 'Webinar must be .mp4';
}
} else {
echo "No File";
}
I get the No File
output. 我得到
No File
输出。
I have ssh'd into the server and the file is not in /tmp/
, /path/to/public_html/tmp/
or path/to/file/tmp/
all of which exist. 我已经进入服务器,文件不在
/tmp/
, /path/to/public_html/tmp/
或path/to/file/tmp/
所有这些path/to/file/tmp/
都存在。
I have tried to use move_uploaded_file()
but as this is executed on all file
inputs I can't get the tmp_name
dynamically due to my limited knowledge of javascript. 我尝试使用
move_uploaded_file()
但是由于在所有file
输入上都执行了此操作,由于我对javascript的了解有限,因此我无法动态获取tmp_name
。
tl;dr version; tl; dr版本; Where is my file gone and how can I find it?
我的文件哪里去了,怎么找到?
NOTE; 注意; This form did work before the APC intevention and I am running wordpress in case that affects anything.
这种形式在APC提出之前确实有效,并且我正在运行wordpress以防万一影响任何事情。
Fixed this one on my own as well. 我自己也解决了这个问题。
In the progress.php
file (found on the other question) I modified the elseif
statement with this: 在
progress.php
文件中(在另一个问题上找到),我用以下命令修改了elseif
语句:
elseif(($s_progressId = $_POST['APC_UPLOAD_PROGRESS']) || ($s_progressId = $_GET['APC_UPLOAD_PROGRESS']))
{
// If the file has finished uploading add content to APC cache
$realpath = realpath($PHP_SELF);
$uploaddir = $realpath . '/tmp/';
foreach ($_FILES as $file) {
if(!empty($file['name'])) {
$uploaded_file = $file['name'];
$moveme = $uploaddir.$uploaded_file;
move_uploaded_file($file['tmp_name'], $moveme);
}
}
apc_store('files_'.$s_progressId, $_FILES);
die();
}
That way I could iterate through the $_FILES
array without knowing the name of the input. 这样,我可以遍历
$_FILES
数组而无需知道输入的名称。 I noticed that it loops through a couple of times hence the if(!empty())
however in hindsight it's probably best practice anyway. 我注意到它循环了几次,因此
if(!empty())
然而,事后看来,这可能还是最佳实践。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.