下面是执行时抛出一些错误的代码。我试图做的是无论如何都会执行代码的最后一行(错误或无错误)。
<?php
require 'main.php';
function create_photo($file_path) {
# Upload the received image file to Cloudinary
@$result = \Cloudinary\Uploader::upload($file_path, array(
"tags" => "backend_photo_album",
));
@unlink($file_path);
error_log("Upload result: " . \PhotoAlbum\ret_var_dump($result));
$photo = \PhotoAlbum\create_photo_model($result);
return $result;
}
$files = $_FILES["files"];
$files = is_array($files) ? $files : array($files);
$files_data = array();
foreach ($files["tmp_name"] as $index => $value) {
array_push($files_data, create_photo($value));
}
?>
<script>window.location.replace('index.html')</script>
非常感谢任何帮助。感谢
答案 0 :(得分:1)
我认为根据你的php版本,你可以使用像这样的“try / catch / finally”集团:
try
{
// code that may throw an exception
}
catch(Exeption $e) // The exception you want to catch
{
// Exception treatment
}
finally
{
// Executed no matter what
}
也许看看如何使用它。