Can I upload a file without using move_uploaded_file?
我可以在不使用move_uploaded_file的情况下上传文件吗?
My steps:
- Upload file using usual form "file", then store the full path of temp file
/tmp/phpwcL9F3
. - Do an AJAX call to
copy()
that temp file to my upload folder.
使用常用表单“file”上传文件,然后存储临时文件/ tmp / phpwcL9F3的完整路径。
执行AJAX调用将临时文件复制()到我的上传文件夹。
Could I do that?
我能这样做吗?
Update: The logic flow I want to implement (actually it's from my customer):
更新:我想实现的逻辑流程(实际上是来自我的客户):
- Choose file, press "Submit" => Processing. A dialog is shown while the process is running. => AJAX file uploading.
- If file existed. Show dialog OK, Cancel. If press Cancel, nothing uploaded. If press OK, it actually uploads the file.
选择文件,按“提交”=>处理。进程运行时会显示一个对话框。 => AJAX文件上传。
如果文件存在。显示对话框确定,取消。如果按取消,则不会上传。如果按OK,它实际上传文件。
4 个解决方案
#1
0
You should also take a look at file_get_content
php function.
你还应该看一下file_get_content php函数。
#2
0
You can use this Fine Uploader This uploads the files in a directory you specify using chunking.
您可以使用此Fine Uploader这将使用分块将文件上载到您指定的目录中。
#3
0
In my case, i have a separate php function that will check if the file is existing or not (ex. fileExisting()). It will be called by ajax when the user clicks on the Upload button (file name will be sent also). When fileExisting() returns true, it will prompt the user if he/she wants to overwrite the file.
在我的情况下,我有一个单独的PHP函数,将检查文件是否存在(例如fileExisting())。当用户点击“上传”按钮时,它将由ajax调用(文件名也将被发送)。当fileExisting()返回true时,它将提示用户是否要覆盖该文件。
If the user selected OK, it will now actually submit the form.
如果用户选择了“确定”,它现在将实际提交表单。
#4
0
I found a solution for this question:
我找到了这个问题的解决方案:
- Actually upload that file to a temporary location.
- When confirming it (pressing OK), move the file to the expected place.
- Finally remove the temporary file.
实际上将该文件上传到临时位置。
确认后(按OK),将文件移动到预期位置。
最后删除临时文件。
After step 1, the file really exists so it has a name and a path so we can check its existence.
在第1步之后,文件确实存在,因此它有一个名称和一个路径,所以我们可以检查它的存在。
#1
0
You should also take a look at file_get_content
php function.
你还应该看一下file_get_content php函数。
#2
0
You can use this Fine Uploader This uploads the files in a directory you specify using chunking.
您可以使用此Fine Uploader这将使用分块将文件上载到您指定的目录中。
#3
0
In my case, i have a separate php function that will check if the file is existing or not (ex. fileExisting()). It will be called by ajax when the user clicks on the Upload button (file name will be sent also). When fileExisting() returns true, it will prompt the user if he/she wants to overwrite the file.
在我的情况下,我有一个单独的PHP函数,将检查文件是否存在(例如fileExisting())。当用户点击“上传”按钮时,它将由ajax调用(文件名也将被发送)。当fileExisting()返回true时,它将提示用户是否要覆盖该文件。
If the user selected OK, it will now actually submit the form.
如果用户选择了“确定”,它现在将实际提交表单。
#4
0
I found a solution for this question:
我找到了这个问题的解决方案:
- Actually upload that file to a temporary location.
- When confirming it (pressing OK), move the file to the expected place.
- Finally remove the temporary file.
实际上将该文件上传到临时位置。
确认后(按OK),将文件移动到预期位置。
最后删除临时文件。
After step 1, the file really exists so it has a name and a path so we can check its existence.
在第1步之后,文件确实存在,因此它有一个名称和一个路径,所以我们可以检查它的存在。