gpt4 book ai didi

javascript - 拖放 uploader

转载 作者:行者123 更新时间:2023-11-28 10:59:00 25 4
gpt4 key购买 nike

我正在尝试制作一个拖放 uploader 。我已经制作了拖放部分,但现在我必须制作 PHP,但我陷入了困境,不知道该怎么做。我的问题是,我无法使用 move_uploaded_file();因为没有

<input type="file">

已提交。有没有办法解决这个问题以及我应该使用/做什么?

我并不是要求完整的代码示例,而是要求我接下来要做什么的线索。

最佳答案

查看this implementation得到一个想法:

/**
* Save the file to the specified path
* @return boolean TRUE on success
*/
function save($path) {
$input = fopen("php://input", "r");
$temp = tmpfile();
$realSize = stream_copy_to_stream($input, $temp);
fclose($input);

if ($realSize != $this->getSize()){
return false;
}

$target = fopen($path, "w");
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);

return true;
}

我在我的一个项目中使用了这样的实现:

$savePath = '/home/user/uploaded_files/picture.png';

if(!isset($_FILES['qqfile']['tmp_name'])) {
$input = fopen('php://input', 'r');
$temp = tmpfile();
stream_copy_to_stream($input, $temp);
fclose($input);
$target = fopen($savePath, 'w');
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
} else {
move_uploaded_file($_FILES['qqfile']['tmp_name'], $savePath);
}

关于javascript - 拖放 uploader ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12570731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com