0

Warning: move_uploaded_file(images/P1_222.jpg): failed to open stream: Permission denied in G:\PleskVhosts\coinvoiture.com\httpdocs\annonces.php on line 423

Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\phpF005.tmp' to 'images/P1_222.jpg' in G:\PleskVhosts\coinvoiture.com\httpdocs\annonces.php on line 423

    $pid = mysqli_insert_id($co);

$valid_formats = array("jpg", "png", "gif", "bmp");
$max_file_size = 1024*500; //100 kb
$path = "admin/images/"; // Upload directory
$count = 1;

if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
    // Loop $_FILES to execute all files
    foreach ($_FILES['files']['name'] as $f => $name) {
        $name="P".$count."_".$pid.".jpg";     
        if ($_FILES['files']['error'][$f] == 4) {
            continue; // Skip file if any error found
        }          
        if ($_FILES['files']['error'][$f] == 0) {              
            if ($_FILES['files']['size'][$f] > $max_file_size) {
                $message[] = "$name is too large!.";
                continue; // Skip large files
            }
            elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
                $message[] = "$name is not a valid format";
                continue; // Skip invalid file formats
            }
            else{ // No error found! Move uploaded files 
                if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name)) {
                    $count++; // Number of successfully uploaded files
                }
            }
        }
    }
}
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345

0 Answers0