PHP/アップロード
if (
isset($_POST["upload_btn_x"])
){
if (
!is_uploaded_file($_FILES["upfile"]["tmp_name"])
) {
$li["err"][] = "ファイルが選択されてません";
} elseif (
!$handle = fopen($_FILES["upfile"]["tmp_name"], "r")
) {
$li["err"][] = "ファイルオープンに失敗";
} else{
if(
!empty($_POST["delete"])
){
$sql = "delete from recruit";
mysql_query($sql);
}
$ct = 0;
$insert_ct = 0;
while (
($buffer = fgetcsv_reg($handle))
) {
mb_convert_variables("utf8", "sjis-win", $buffer);
}
fclose($handle);
$filename = date("Ymd_His");
$filename .= "_". $_FILES["upfile"]["name"];
move_uploaded_file($_FILES["upfile"]["tmp_name"], "csv/{$filename}");
chmod("csv/{$filename}", 0666);
$li["msg"][] = "{$insert_ct}件登録しました。";
}
}
//___ ERRORの参考になる
/*
switch ($_FILES["upfile"]["error"]) {
case UPLOAD_ERR_INI_SIZE:
$message = "The uploaded file exceeds the upload_max_filesize directive in php.ini";
break;
case UPLOAD_ERR_FORM_SIZE:
$message = "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form";
break;
case UPLOAD_ERR_PARTIAL:
$message = "The uploaded file was only partially uploaded";
break;
case UPLOAD_ERR_NO_FILE:
$message = "No file was uploaded";
break;
case UPLOAD_ERR_NO_TMP_DIR:
$message = "Missing a temporary folder";
break;
case UPLOAD_ERR_CANT_WRITE:
$message = "Failed to write file to disk";
break;
case UPLOAD_ERR_EXTENSION:
$message = "File upload stopped by extension";
break;
default:
$message = "Unknown upload error";
break;
}
return $message;
*/
<html>
<form method="post" action="import.html" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="33554432" />
<input type="file" name="upfile" />
<input type="submit" name="upload_btn_x" value="求人データインポート" />
</form>
</html>
___ Thanks.
エラーメッセージの説明
http://www.php.net/manual/ja/features.file-upload.errors.php
upload