Jump to content

Recommended Posts

This is my code:

 


//Manage image upload and put into directory: 
if(($_FILES["image"]["type"] == "image/jpg") || 
($_FILES["file"]["type"] == "image/jpeg"))
{
if ($_FILES["image"]["error"] > 0)
{
	echo "Return Code: " . $_FILES["image"]["error"] . "<br />";
}
else
{
	if(file_exists("../images/" . $_FILES['image']['name']))
	{
		echo 'Error: File already exists';
	}
	else
	{
		move_uploaded_file($_FILES["image"]["tmp_name"],  
		"../images/" . $_FILES["image"]["name"]);
		echo "Stored in: " . "../images/" . $_FILES["image"]["name"];
	}
}
}
else
{
echo 'Invalid file type';
}

 

When i upload a file using a form, that's the right file type, it always returns invalid file type.

 

I think the problem is with;

 

if(($_FILES["image"]["type"] == "image/jpg") || 
($_FILES["file"]["type"] == "image/jpeg"))

Link to comment
https://forums.phpfreaks.com/topic/205932-problem-determining-file-type-in-_file/
Share on other sites

Well part of the problem could be that you are using "file" in the second part of the if / or statement instead of "image".

 

To make sure the value is what it should be echo it out for debugging, as PHP is case sensitive and that could be a potential issue too.

Hey thanks that helped :)

 

But now i think there's a problem with my hosting. i got the following error:

 

Warning: move_uploaded_file(214047) [function.move-uploaded-file]: failed to open stream: Permission denied in [LOCATION OF MY SCRIPT ON THE SERVER] on line 34

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\Temp\php\php7C77.tmp' to '214047' in [LOCATION OF MY SCRIPT ON THE SERVER] on line 34

 

I'm guessing this has something to do with my hosting? I'm calling them atm to see if they can resolve it, because it doesn't look like an error with the PHP to me.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.