Это рабочий пример.
Форма HTML:
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="512000" />
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>
Код PHP:
<?php
$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename( Это рабочий пример.
Форма HTML:
[110] Код PHP:
[111]FILES['userfile']['name']);
echo "<p>";
if (move_uploaded_file( Это рабочий пример.
Форма HTML:
[110] Код PHP:
[111]FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Upload failed";
}
echo "</p>";
echo '<pre>';
echo 'Here is some more debugging info:';
print_r( Это рабочий пример.
Форма HTML:
[110] Код PHP:
[111]FILES);
print "</pre>";
?>
With the power of grep
my @matching_items = grep {
$_->{id} == 21
} @array_data_or;
If you know there will be only one item returned you can just do this:
my ($item) = grep {
$_->{id} == 21
} @array_data_or;
(Untested, and I haven't written one of these in a while, but this should work)
If you're sure that the search always returns only one occurence or if you're interested in only the first match then you could use the 'first' subroutine found in List::Util
use List::Util;
my %matching_hash = %{ first { $_->{id} == 21 } @array_data_or };
I enclosed the subroutine call in the %{ } block to ensure that the RHS evaluates to a hash.