Ragazzi, ho questa piccola funzione...dopo ho del codice che mi aggiorna il database, però vorrei che lo eseguisse solamente nel caso questa funzione mi andasse a buon fine (cioè facesse l'upload del file), la soluzione che ho trovato io è di mettere il codice nell'ultimo "if", però secondo me esiste qualche soluzione + raffinata per farlo.
Codice PHP:
if (!is_writable($upl_path)){
printf(__("It doesn't look like you can use the file upload feature at this time because the directory you have specified (<code>%s</code>) doesn't appear to be writable by WordPress. Check the permissions on the directory and for typos."), ABSPATH.'/'.get_settings('upload_path').$rel_path);
}
else {
$allowed_types = explode(' ', trim(strtolower($imagesallowed)));
$img1_name = $_FILES['upl_file']['name'];
$img1 = $_FILES['upl_file']['tmp_name'];
$imgtype = explode(".",$img1_name);
$imgtype = strtolower($imgtype[count($imgtype)-1]);
//check that this is an image, no funnybusiness
$checkthatimage = getimagesize($img1);
if ($checkthatimage == FALSE) {
unlink($img1);
die (__("Not a valid image file."));
}
//end check
if (in_array($imgtype, $allowed_types) == false) {
echo sprintf(__('File %1$s of type %2$s is not allowed.') , $img1_name, $imgtype);
}
else {
if( $_FILES['upl_file']['size'] > ($maxuploadsize*1024))
echo __("File is larger than allowed limit!");
else {//filesize is OK
if($_FILES['upl_file']['size'] > 0){//larger than 0 is allowed:o)
$pathtofile2 = $upl_path.$img1_name;
if(file_exists($pathtofile2)){
printf(__("The filename '%s' already exists!"), $img1_name);
}
else {
//let's move the file
$moved = move_uploaded_file($img1, $pathtofile2);
// if move_uploaded_file() fails, try copy()
if (!$moved) {
$moved = copy($img1, $pathtofile2);
}
if (!$moved) {
printf(__("Couldn't upload your file to %s."), $pathtofile2);
} else {
chmod($pathtofile2, 0666);
@unlink($img1);