23
Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.
Tôi có một biểu mẫu [HTML, PHP] cho phép người dùng cuối tải lên một tệp để cập nhật cơ sở dữ liệu [MySQL] với các bản ghi trong tệp được tải lên [cụ thể là .csv]. Tuy nhiên, trong PHPScript, tôi chỉ có thể nhận tên tệp và không phải là đường dẫn hoàn chỉnh của tệp được cụ thể. Fopen [] thất bại vì lý do này. Bất cứ ai có thể vui lòng cho tôi biết làm thế nào tôi có thể làm việc để tìm con đường hoàn chỉnh?
Mã HTML:
File to upload :
Kịch bản PHP:
Đã hỏi ngày 27 tháng 3 năm 2011 lúc 16:55Mar 27, 2011 at 16:55
name_maskedname_maskedname_masked
9.40639 Huy hiệu vàng113 Huy hiệu bạc171 Huy hiệu đồng39 gold badges113 silver badges171 bronze badges
3
name
đề cập đến tên tệp ở phía máy khách. Để lấy tên tệp [bao gồm cả đường dẫn đầy đủ] ở phía máy chủ, bạn cần sử dụng tmp_name
:client-side. To get the filename [including the full path]
on the server-side, you need to use tmp_name
:
$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
Đã trả lời ngày 27 tháng 3 năm 2011 lúc 17:03Mar 27, 2011 at 17:03
$target='uploads/'.basename[$_FILES['UploadFileName']['name']];
if[move_uploaded_file[$_FILES['UploadFileName']['tmp_name'],$target]] {
//Insert into your db
$fp = fopen[$target, "r"];
}
Đã trả lời ngày 8 tháng 11 năm 2012 lúc 10:33Nov 8, 2012 at 10:33
ShivarajrhshivarajrhShivarajRH
87211 Huy hiệu bạc23 Huy hiệu đồng11 silver badges23 bronze badges
Tôi đã viết như thế này:
$filePath = realpath[$_FILES["file"]["tmp_name"]];
Điều này đã cho tôi đường dẫn đầy đủ đến tệp đã tải lên trong PHP. Nếu bạn tìm thấy vấn đề 0 byte trong tải xuống tệp, chỉ cần sửa đổi dòng nội dung này như thế này
header["Content-Length: ".filesize[$filePath]];
Trong đó $ filepath nên là đường dẫn tuyệt đối để tập tin không chỉ xử lý tệp.
Đã trả lời ngày 16 tháng 1 năm 2014 lúc 11:19Jan 16, 2014 at 11:19
Webbloverwebbloverwebblover
9882 Huy hiệu vàng12 Huy hiệu bạc28 Huy hiệu đồng2 gold badges12 silver badges28 bronze badges
Sử dụng mã sau,
$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
Đã trả lời ngày 9 tháng 1 năm 2012 lúc 12:15Jan 9, 2012 at 12:15
Vijin Paulrajvijin PaulrajVijin Paulraj
4.4014 Huy hiệu vàng39 Huy hiệu bạc52 Huy hiệu Đồng4 gold badges39 silver badges52 bronze badges
Tôi sử dụng như thế này ...
Đã trả lời ngày 12 tháng 3 năm 2018 lúc 19:47Mar 12, 2018 at 19:47
ineedmynetwork.com
Brentwientjes tại Nospam dot comast dot net ¶ — Moves an uploaded file to a new location
13 năm trước
Labsy tại Seznam dot org ¶[string
0, string
1]: bool
11 năm trước
Thông số
2Tên tệp của tệp đã tải lên.
3Đích của tập tin di chuyển.
Trả về giá trị
Trả lại
4 khi thành công.
4 on success. Nếu
2 không phải là tệp tải lên hợp lệ, thì sẽ không có hành động nào xảy ra và Move_uploaded_file [] sẽ trả về
6.move_uploaded_file[] will return
6. Nếu
2 là tệp tải lên hợp lệ, nhưng không thể di chuyển vì một số lý do, sẽ không có hành động nào xảy ra và di chuyển_uploaded_file [] sẽ trả về
6. Ngoài ra, một cảnh báo sẽ được đưa ra.move_uploaded_file[] will return
6. Additionally, a warning will be issued. Ví dụ
Ví dụ #1 Tải lên nhiều tệp
9Ghi chú
Ghi chú::
Move_Uploaded_file [] là Open_basingir Aware. Tuy nhiên, các hạn chế chỉ được đặt trên đường dẫn
3 để cho phép di chuyển các tệp được tải lên trong đó
2 có thể mâu thuẫn với các hạn chế đó. Move_uploaded_file [] đảm bảo sự an toàn của hoạt động này bằng cách chỉ cho phép các tệp đó được tải lên thông qua PHP được di chuyển. is open_basedir aware. However, restrictions are placed only on the
3 path as to allow the moving of uploaded files in which
2 may conflict with such restrictions. move_uploaded_file[] ensures the safety of this operation by allowing only those files uploaded through PHP to be moved.
Cảnh báo
Nếu tệp đích đã tồn tại, nó sẽ bị ghi đè.
Xem thêm
- is_uploaded_file [] - cho biết liệu tệp có được tải lên qua bài đăng http
- Đổi tên [] - Đổi tên một tệp hoặc thư mục
- Xem tải lên tệp xử lý để biết ví dụ sử dụng đơn giản
Yousef Ismaeil cliprz ¶ ¶
9 năm trước
$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
2$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
3$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
4$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
5$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
6$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
7$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
8$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
9$target='uploads/'.basename[$_FILES['UploadFileName']['name']];
if[move_uploaded_file[$_FILES['UploadFileName']['tmp_name'],$target]] {
//Insert into your db
$fp = fopen[$target, "r"];
}
0$target='uploads/'.basename[$_FILES['UploadFileName']['name']];
if[move_uploaded_file[$_FILES['UploadFileName']['tmp_name'],$target]] {
//Insert into your db
$fp = fopen[$target, "r"];
}
1$target='uploads/'.basename[$_FILES['UploadFileName']['name']];
if[move_uploaded_file[$_FILES['UploadFileName']['tmp_name'],$target]] {
//Insert into your db
$fp = fopen[$target, "r"];
}
2$target='uploads/'.basename[$_FILES['UploadFileName']['name']];
if[move_uploaded_file[$_FILES['UploadFileName']['tmp_name'],$target]] {
//Insert into your db
$fp = fopen[$target, "r"];
}
3$target='uploads/'.basename[$_FILES['UploadFileName']['name']];
if[move_uploaded_file[$_FILES['UploadFileName']['tmp_name'],$target]] {
//Insert into your db
$fp = fopen[$target, "r"];
}
4Dan Delaney ¶ ¶
14 năm trước
$target='uploads/'.basename[$_FILES['UploadFileName']['name']];
if[move_uploaded_file[$_FILES['UploadFileName']['tmp_name'],$target]] {
//Insert into your db
$fp = fopen[$target, "r"];
}
5Juliano P. Santos ¶ ¶
3 năm trước
$target='uploads/'.basename[$_FILES['UploadFileName']['name']];
if[move_uploaded_file[$_FILES['UploadFileName']['tmp_name'],$target]] {
//Insert into your db
$fp = fopen[$target, "r"];
}
6Zarel ¶ ¶
16 năm trước
$target='uploads/'.basename[$_FILES['UploadFileName']['name']];
if[move_uploaded_file[$_FILES['UploadFileName']['tmp_name'],$target]] {
//Insert into your db
$fp = fopen[$target, "r"];
}
7$target='uploads/'.basename[$_FILES['UploadFileName']['name']];
if[move_uploaded_file[$_FILES['UploadFileName']['tmp_name'],$target]] {
//Insert into your db
$fp = fopen[$target, "r"];
}
8$target='uploads/'.basename[$_FILES['UploadFileName']['name']];
if[move_uploaded_file[$_FILES['UploadFileName']['tmp_name'],$target]] {
//Insert into your db
$fp = fopen[$target, "r"];
}
9$filePath = realpath[$_FILES["file"]["tmp_name"]];
0$filePath = realpath[$_FILES["file"]["tmp_name"]];
1Florian S. ở H. An der E. [.de] ¶ ¶
14 năm trước
$filePath = realpath[$_FILES["file"]["tmp_name"]];
2$filePath = realpath[$_FILES["file"]["tmp_name"]];
3$filePath = realpath[$_FILES["file"]["tmp_name"]];
4Juliano P. Santos ¶ ¶
3 năm trước
$filePath = realpath[$_FILES["file"]["tmp_name"]];
5Zarel ¶ ¶
16 năm trước
$filePath = realpath[$_FILES["file"]["tmp_name"]];
6$filePath = realpath[$_FILES["file"]["tmp_name"]];
7$filePath = realpath[$_FILES["file"]["tmp_name"]];
8$filePath = realpath[$_FILES["file"]["tmp_name"]];
9header["Content-Length: ".filesize[$filePath]];
0$filePath = realpath[$_FILES["file"]["tmp_name"]];
4Florian S. ở H. An der E. [.de] ¶ ¶
nlgordon tại iastate dot edu ¶
header["Content-Length: ".filesize[$filePath]];
215 năm trước ¶
Mancow tại MacFilez Dot Net
header["Content-Length: ".filesize[$filePath]];
3ccbsschucko tại gmail dot com ¶ ¶
3 năm trước
header["Content-Length: ".filesize[$filePath]];
4header["Content-Length: ".filesize[$filePath]];
5header["Content-Length: ".filesize[$filePath]];
6$filePath = realpath[$_FILES["file"]["tmp_name"]];
4Zarel ¶ ¶
16 năm trước
header["Content-Length: ".filesize[$filePath]];
8header["Content-Length: ".filesize[$filePath]];
9$filePath = realpath[$_FILES["file"]["tmp_name"]];
4Florian S. ở H. An der E. [.de] ¶ ¶
nlgordon tại iastate dot edu ¶
$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
1$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
2$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
3$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
4$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
5$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
6$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
7$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
815 năm trước ¶
Mancow tại MacFilez Dot Net
$handle = fopen[$_FILES["UploadFileName"]["tmp_name"], 'r'];
9ccbsschucko tại gmail dot com ¶ ¶
3 năm trước
0Zarel ¶ ¶
16 năm trước
1Florian S. ở H. An der E. [.de] ¶ ¶
nlgordon tại iastate dot edu ¶
2
3
4
5
6
7$filePath = realpath[$_FILES["file"]["tmp_name"]];
415 năm trước ¶
Mancow tại MacFilez Dot Net
9ccbsschucko tại gmail dot com ¶ ¶
14 năm trước
name
0
name
1
name
2
$filePath = realpath[$_FILES["file"]["tmp_name"]];
4Juliano P. Santos ¶ ¶
3 năm trước
name
4
name
5
name
6
name
7
$filePath = realpath[$_FILES["file"]["tmp_name"]];
4Zarel ¶ ¶
nlgordon tại iastate dot edu ¶
name
9
tmp_name
0
tmp_name
1
tmp_name
215 năm trước ¶
Mancow tại MacFilez Dot Net
tmp_name
3
tmp_name
4
tmp_name
5
tmp_name
6
tmp_name
7
$filePath = realpath[$_FILES["file"]["tmp_name"]];
4ccbsschucko tại gmail dot com ¶ ¶
Mancow tại MacFilez Dot Net
tmp_name
9
ccbsschucko tại gmail dot com ¶ ¶
4 năm trước
00
01
02$filePath = realpath[$_FILES["file"]["tmp_name"]];
4Jest3r tại Mtonic Dot Net ¶
nlgordon tại iastate dot edu ¶
0415 năm trước ¶
Mancow tại MacFilez Dot Net
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23$filePath = realpath[$_FILES["file"]["tmp_name"]];
4ccbsschucko tại gmail dot com ¶ ¶
4 năm trước
25
26$filePath = realpath[$_FILES["file"]["tmp_name"]];
4Jest3r tại Mtonic Dot Net ¶
3 năm trước
28
29
30$filePath = realpath[$_FILES["file"]["tmp_name"]];
4Zarel ¶ ¶
3 năm trước
32
33$filePath = realpath[$_FILES["file"]["tmp_name"]];
4Zarel ¶ ¶
14 năm trước
35
36
37Juliano P. Santos ¶ ¶
16 năm trước
38
39
40
41
42$filePath = realpath[$_FILES["file"]["tmp_name"]];
4Florian S. ở H. An der E. [.de] ¶ ¶
nlgordon tại iastate dot edu ¶
4415 năm trước ¶
3 năm trước
45
46
47
48
49
50
51$filePath = realpath[$_FILES["file"]["tmp_name"]];
4Zarel ¶ ¶
3 năm trước
53
54
55$filePath = realpath[$_FILES["file"]["tmp_name"]];
4Zarel ¶ ¶
Mancow tại MacFilez Dot Net
57
58$filePath = realpath[$_FILES["file"]["tmp_name"]];
4ccbsschucko tại gmail dot com ¶ ¶
4 năm trước
60
61$filePath = realpath[$_FILES["file"]["tmp_name"]];
4