Hello, I am trying to rename a file, and then if the file is there, upload it. I always get the message uploading failed though, here is what I am trying to do:

	$k = 0;
	foreach($_FILES["pics"]["name"] as $key => $current)
	{
		switch($k)
		{
			case 0:
			$uploadfile = $uploaddir . basename("pic1jpg");
			break;
			case 1:
			$uploadfile = $uploaddir . basename("pic2.jpg");
			break;
			case 2:
			$uploadfile = $uploaddir . basename("pic3.jpg");
			break;
		}

	if($current != "")
	{
		if (!move_uploaded_file($_FILES["pics"]["tmp_name"][$key], $uploadfile))
		{
	    	echo "{$current} uploading failed.";
		}
	}	
	$k++;
}

    Try turning on all error reporting to see if it's something like a permissions problem:

    <?php
    ini_set('display_errors', 1); // change to 0 for production version
    error_reporting(E_ALL);
    // rest of script...
    ?>
    

      You should also be checking the ['error'] index for each upload to ensure that it is UPLOAD_ERR_OK. Check out example #3 on this manual page for a coding example: [man]file-upload[/man].

        Write a Reply...