Yanor.net/
Wiki
Blog
GitHub
Sandbox
開始行:
* PHP画像アップロード [#t1dc950c]
** HTML [#e0ddc6f4]
<form action="test.php" method="post" enctype="multipart...
<input type="hidden" name="MAX_FILE_SIZE" value="200000"...
<input name="image1" type="file" />
<input name="image2" type="file" />
</form>
** PHP [#ebf03f29]
try {
$id = 100;
$image_dir = '/var/www/image';
$errs = array(
UPLOAD_ERR_OK => 'There is no error, the...
UPLOAD_ERR_INI_SIZE => 'The uploaded file exce...
UPLOAD_ERR_FORM_SIZE => 'The uploaded file exce...
UPLOAD_ERR_PARTIAL => 'The uploaded file was ...
UPLOAD_ERR_NO_FILE => 'No file was uploaded.',
UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary fo...
UPLOAD_ERR_CANT_WRITE => 'Failed to write file t...
UPLOAD_ERR_EXTENSION => 'File upload stopped by...
);
foreach (array('image1','image2') as $k) {
while (true) {
if (!isset($_FILES[$k])) break;
if (!isset($_FILES[$k]['type'])) break;
list($type) = split('/',$_FILES[$k]['type']);
if ($type != 'image') break;
if (isset($_FILES[$k]['error']) && $_FILES[$...
throw new Exception('ファイルアップロー...
}
$suffix = strtolower(substr($_FILES[$k]['nam...
if (!in_array($suffix,array('jpg','jpeg','gi...
if (!is_dir("$image_dir/$id")) {
mkdir("$image_dir/$id");
chmod("$image_dir/$id",0777);
}
foreach (array('jpg','jpeg','gif','png') as ...
if (file_exists("$image_dir/$id/$k.$v"))...
}
move_uploaded_file($_FILES[$k]['tmp_name'], ...
chmod("$image_dir/$id/$k.$suffix",0666);
break;
}
}
} catch (Exception $e) {
die($e->getMessage());
}
終了行:
* PHP画像アップロード [#t1dc950c]
** HTML [#e0ddc6f4]
<form action="test.php" method="post" enctype="multipart...
<input type="hidden" name="MAX_FILE_SIZE" value="200000"...
<input name="image1" type="file" />
<input name="image2" type="file" />
</form>
** PHP [#ebf03f29]
try {
$id = 100;
$image_dir = '/var/www/image';
$errs = array(
UPLOAD_ERR_OK => 'There is no error, the...
UPLOAD_ERR_INI_SIZE => 'The uploaded file exce...
UPLOAD_ERR_FORM_SIZE => 'The uploaded file exce...
UPLOAD_ERR_PARTIAL => 'The uploaded file was ...
UPLOAD_ERR_NO_FILE => 'No file was uploaded.',
UPLOAD_ERR_NO_TMP_DIR => 'Missing a temporary fo...
UPLOAD_ERR_CANT_WRITE => 'Failed to write file t...
UPLOAD_ERR_EXTENSION => 'File upload stopped by...
);
foreach (array('image1','image2') as $k) {
while (true) {
if (!isset($_FILES[$k])) break;
if (!isset($_FILES[$k]['type'])) break;
list($type) = split('/',$_FILES[$k]['type']);
if ($type != 'image') break;
if (isset($_FILES[$k]['error']) && $_FILES[$...
throw new Exception('ファイルアップロー...
}
$suffix = strtolower(substr($_FILES[$k]['nam...
if (!in_array($suffix,array('jpg','jpeg','gi...
if (!is_dir("$image_dir/$id")) {
mkdir("$image_dir/$id");
chmod("$image_dir/$id",0777);
}
foreach (array('jpg','jpeg','gif','png') as ...
if (file_exists("$image_dir/$id/$k.$v"))...
}
move_uploaded_file($_FILES[$k]['tmp_name'], ...
chmod("$image_dir/$id/$k.$suffix",0666);
break;
}
}
} catch (Exception $e) {
die($e->getMessage());
}
ページ名: