Jump to content

Inserting images using $_FILES


Tenaciousmug

Recommended Posts

Ok, I have this working on another page from a long time ago, but it's not working right here: It gets past the if($num == 0) part, but when it's seeing if the files has been uploaded, it's not getting past that and it won't give me my error message too. So I have a feeling it's getting past it, but it's not uploading it into the software/ directory and not inserting it into the database.

I get no errors in my error_log or my default errors I have set up under the variable, $message.

 

$target_path = "software/";
$basename = strtolower(basename($_FILES['softwarePath']['name']));

$target_path = $target_path . $basename;
$sql = "SELECT softwarePath FROM software WHERE softwarePath='$target_path'";
$result = mysqli_query($cxn, $sql) or die(mysqli_error());
$num = mysqli_num_rows($result);
if($num == 0)
{
if(move_uploaded_file($_FILES['softwarePath']['tmp_name'], $target_path))
{
	$sql = "INSERT INTO software(softwareName,softwareType,softwareDesc,softwarePath,ITOnly) VALUES('$softwareName','$softwareType','$softwareDesc','$target_path','$ITOnly')";
	mysqli_query($cxn,$sql) or die(mysqli_error());
	header("Location: search_software.php");
}
}
else
{
$message = "There is already a file with that name.";
}

Link to comment
https://forums.phpfreaks.com/topic/254752-inserting-images-using-_files/
Share on other sites

Yeah you're right. It's only showing the target_path and not even the basename variable so it's obviously not grabbing it.

Ok here is the HTML part for my file upload:

<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Software Upload:<br />
<input name="softwarepath" type="file" /><br />

 

And the PHP:

$target_path = "software/";
$basename = strtolower(basename($_FILES['softwarepath']['name']));

$target_path = $target_path . $basename;
echo $target_path;

 

It won't echo the target_path though..

I've looked up many tutorials and still can't find an answer. D:

I see this getting pushed down really far and just wanted to move it back up so maybe someone can still help me?

 

It's only echoing "software/".

It's not echoing the file i uploaded, but I checked the "name" attribute in the form and the name it's pulling and they both are the same..

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.