下面是在执行时引发一些错误的代码。我想做的是无论什么(错误或无错误)都将执行代码的最后一行。
<?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>
任何帮助将非常感激。谢谢
最佳答案
我认为根据您的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
}
也许看看如何使用它。