Jump to content

[SOLVED] Having problems with uploading an image


IronWarrior

Recommended Posts

Have this so far, no errors, it just does nothing, doesnt echo OR create a new directory...

 

//If all fields have been completed, then continue. 
	else 
	{
		// Checking if an image has been uploaded
		if (is_uploaded_file($imgfile))
		{
			// Checking if a directory already exists for the file
			if (is_dir($trimmedVehicleName)== false)
			{
				// Creating a directory if the directory does not exist
				echo "Directory does not exist";
				mkdir($trimmedVehicleName);
			}
			//Copying the file to the directory
			if (!copy($imgfile, $newName))
			{
				print "Error Uploading File.";
				exit();
			}
		}
	}

There is really no way to help you based on that small section of code. For example, where is $imgfile getting set? Is your code checking for upload errors?

 

What have you done to troubleshoot this? Have you echoed (using print_r()) out the $_FILES array to see what it contains?

Sorry, here is the form code:

 

<h3> 
List an item 
</h3>
<p>
This is the section of the website where you can list a new item for sale. 
</p>
<form action="index.php?page=submitAnItem" enctype="multipart/form-data" method="post">
Vehicle Name: 
<input type="text" name="vehicleName" size="35"> 
<br /> 
Vehicle Description:
<textarea name="vehicleDescription" cols="60" rows="30"></textarea>
<br /> 
Vehicle Price
<input type="text" name="vehiclePrice"> 
<br />
Vehicle Type
<input type="text" name="vehicleType">
<br />
Vehicle Category
<br />
<input type="radio" name="vehicleCategory" value="1"> Armoured Vehicle
<br />
<input type="radio" name="vehicleCategory" value="2"> Truck
<br />
<input type="radio" name="vehicleCategory" value="3"> Jeep
<br /> 
Upload Images:
<br />
<input type="hidden" name="MAX_FILE_SIZE" value="3000000">
<input type="file" name="imgfile"> 
<br />
<input type="file" name="file[]">
<br />
<input type="file" name="file[]">
<br />
<input type="file" name="file[]">   	
<br />
<input type="hidden" name="validTransaction" value="true">
<input type="submit" value="Submit Listing"> 
</form>

 

Here is the complete PHP code:

<?php 
if (isset($_POST["validTransaction"]))
{
	$vehicleName = $_POST["vehicleName"];
	$vehicleDescription = $_POST["vehicleDescription"];
	$vehiclePrice = $_POST["vehiclePrice"];
	$vehicleType = $_POST["vehicleType"];
	$vehicleCategory = $_POST["vehicleCategory"];
	$trimmedVehicleName = str_replace(" ","",$vehicleName);
	$folderLocation = "images/".$trimmedVehicleName;
	$currentTime = time();
	$newName = $folderLocation."/".$currentTime.$trimmedVehicleName.".jpg";

	//Checking if all fields are present 
	if ($vehicleName == "" || $vehicleDescription == "" || $vehiclePrice == "" || $vehicleType == "" || $vehicleCategory == "")
	{
		echo "Not all infomation has been completed, please use the return button to re-submit the infomation";
		$error = true;
	}
	//If all fields have been completed, then continue. 
	else 
	{
		// Checking if an image has been uploaded
		if (is_uploaded_file($imgfile))
		{
			// Checking if a directory already exists for the file
			if (is_dir($trimmedVehicleName)== false)
			{
				// Creating a directory if the directory does not exist
				echo "Directory does not exist";
				mkdir($trimmedVehicleName);
			}
			//Copying the file to the directory
			if (!copy($imgfile, $newName))
			{
				print "Error Uploading File.";
				exit();
			}
		}
	}
}
else 
{
	echo "Invalid Transaction";
}
?>

 

For some strange reason I wasnt allowed to edit my post; so I did a print_r on the $_FILES:

 

Array ( [imgfile] => Array ( [name] => Web_T55_AM2_Qtr_Front2.jpg [type] => image/jpeg [tmp_name] => C:\Windows\Temp\php61BA.tmp [error] => 0 => 43235 ) )

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.