Php script: unable to upload files

Hello,

PHP file upload script.

Problem: Unable to upload file under ubuntu server.

I have 2 different webservers setup:

  1. xampp on usb and my problametic script works.
  2. ubuntu server, exact same php script but it wont upload the file.

What i noticed with xampp: <–works
echo “<br>tempFile=>:-”. $_FILES[‘data’][‘tmp_name’][$x] . “<br>”;
result: tempFile=>:-G:\xampp\ mp\php2D.tmp
print_r($imagearray);
Array ( [0] => Array ( [1] => G:\xampp\ mp\php2D.tmp [2] => 1357153942_robinuser_dog.jpg ) )

What i noticed with Ubuntu server:
echo “<br>tempFile=>:-”. $_FILES[‘data’][‘tmp_name’][$x] . “<br>”;
tempFile=>:/tmp/phpzN6e8U <– looks like the “tmp” extension is missing.
print_r($imagearray);
Array ( [0] => Array ( [1] => /tmp/phpzN6e8U [2] => 1357153182_robinuser_bird.jpg ) )

if the temp file ext is missing how do I fix this??

Any help you can provide would be greatly appreciated


?PHP
include('connection.php');
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"&gt;&lt;/script&gt;
&lt;!-- CSS --&gt;
&lt;style type="text/css"&gt;
div.color {
  border-width:2px;
  border-style:solid;
  border-color:#black;
  padding: 3 3 3 3px;
  width: 400px;
  }
&lt;/style&gt;

  &lt;!--  Java script --&gt;
&lt;script&gt;
$(function(){
    $('#add-file-field').click(function(){
		$("#text").append('&lt;div class="added-field"&gt;&lt;input type="file" name="data[]"&gt;&lt;input type="image" src="delete.png" class="remove-btn" value="Remove"&gt;&lt;/div&gt;');
    });
    $('.remove-btn').live('click',function(){
		$(this).parent().remove();
	});
	});
&lt;/script&gt;
&lt;/head&gt;

&lt;?php
	$imageUserId = 'robinuser';
		
	$allowedUpload = 6;  // number of file the user can upload
	$allowedExts = array("jpg", "jpeg", "gif", "png");
	$remove_these = array(' ','`','"','\\'','\\\\','/');
	$upload_directory = 'uploads/'; //image upload folder
	$fileSize = 20000;
	$imagearray=array(); 	
	
	if(isset($_POST['btnsave']))
	{	for($x=0; $x&lt;count($allowedUpload); $x++)
		{	echo "&lt;br&gt;tempFile=&gt;:-". $_FILES['data']['tmp_name'][$x] . "&lt;br&gt;";
			if(!empty($_FILES['data']['name'][$x]))
			{	$extension = end(explode(".", $_FILES['data']['name'][$x]));
				if ((($_FILES["data"]["type"][$x] == "image/gif")
					|| ($_FILES["data"]["type"][$x] == "image/jpeg")
					|| ($_FILES["data"]["type"][$x] == "image/png")
					|| ($_FILES["data"]["type"][$x] == "image/pjpeg"))
					&& ($_FILES["data"]["size"][$x] &lt; $fileSize)
					&& in_array($extension, $allowedExts))
				{	if ($_FILES["data"]["error"][$x] &gt; 0)
					{	echo "Error: " . $_FILES["data"]["error"][$x] . "&lt;br&gt;"; }
					else
					{	//Sanitize the filename
						$sanitizedName = str_replace($remove_these, '', $_FILES['data']['name'][$x]);
						$newImageName = time()."_".$imageUserId."_".$sanitizedName;
						//move_uploaded_file($_FILES['data']['tmp_name'][$x], $upload_directory . $newImageName);
						if(!empty($newImageName))
						{	$imagearray[$x][1] = $_FILES['data']['tmp_name'][$x];
							$imagearray[$x][2] = $newImageName;
						}								
					}
				}
				else
				{	echo "Invalid file: ".$_FILES["data"]["name"][$x];  }
			}// end of IF- if(!empty($_FILES['data']['name'][$x]))
		} // endo for loop
		print_r($imagearray);
		for($y=0; $y&lt; count($imagearray); $y++)
		{	move_uploaded_file($imagearray[$y][1], $upload_directory . $imagearray[$y][2]);	
			echo $imagearray[$y][1] . " " .$upload_directory . $imagearray[$y][2]."&lt;br&gt;";
		}				
	} // end of upload button
?&gt;
&lt;body&gt;
&lt;form enctype="multipart/form-data" action="" method="POST"&gt;
   	&lt;div class="color"&gt;
	Upload:
	&lt;br&gt; - Excepted file formats: ing: JPEG, PNG, & GIF formats.
	&lt;br&gt; - Max number of files you can upload: 6
	&lt;hr&gt;
        &lt;div id="text"&gt;
            &lt;div &gt;&lt;input name="data[]" id="file" type="file" multiple="multiple" /&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;img src="add.jpg"  id="add-file-field" name="add" style="margin-top:21px;"/&gt;
        &lt;input type="submit" name="btnsave" value="Upload File" /&gt;
	&lt;/div&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;

Have you checked the read and write permissions in the destination folder?

The filename of those temporary files should not matter at all to your script. Why do you care so much that the extension is missing? As far as I can see your script would work just fine, and if it doesn’t I can assure you the problem does not lie with the missing extension.

Could you put var_dump($_FILES[‘data’]) and give us the output? I believe you have an error with the upload process, and there is data within the array that will help us identify the problem.

Hello

var_dump($_FILES[‘data’]); results:

array(5) { [“name”]=> array(1) { [0]=> string(8) “bird.jpg” } [“type”]=> array(1) { [0]=> string(10) “image/jpeg” } [“tmp_name”]=> array(1) { [0]=> string(14) “/tmp/phpymaAFB” } [“error”]=> array(1) { [0]=> int(0) } [“size”]=> array(1) { [0]=> int(5537) } }

Okay, so there isn’t an error with the file that is being uploaded (such as size limit). Now I’d recommend turning on error reporting to see if any other errors are being created/hidden.

ini_set("error_reporting", E_ALL ^ E_NOTICE); 
ini_set("display_errors", 1);