Jump to content

Recommended Posts

This is my form

<form method="post" name="add_item" enctype="multipart/form-data" action="add_item.php">

<input name="uploaded_image" type="file" />

<input type="submit" value="Add Item" name="submit" size="30" />

 

 

my php code

 

<?php

if(isset($_post['submit']))
{


$target_path = "images_item/";



if (!($_FILES["uploaded_image"]["type"] == "image/gif" || $_FILES["uploaded_image"]["type"] == "image/jpeg" || $_FILES["uploaded_image"]["type"] == "image/png") && $_FILES["uploaded_image"]["error"] != "4")

{
	//invalid file format
}	
else
{
	move_uploaded_file($_FILES["uploaded_image"]["tmp_name"], $target_path);

}


}

?>

 

 

The folder images_item is on the root but the code is not working as images that have been uploaded are nowhere to be found on images_item folder.

 

 

Anyone?

Link to comment
https://forums.phpfreaks.com/topic/265795-move_uploaded_file-is-not-working/
Share on other sites

1. Uppercase $_POST. Variables are case-sensitive.

2. $target_path has to include the filename.

3. $_FILES[...]["type"] cannot be trusted. Use getimagesize to determine if the file is an image.

4. Your logic is a bit wrong.

5. You also need to check for other error codes. At the very least do an ==UPLOAD_ERR_OK.

6. Make sure your filename is safe. Has the right extension according to the type of image. Again, can't trust the $_FILES[...]["name"] to have the right extension - you need to set it yourself.

Hi

 

There are several realy good tutorials on uploading images. I would check out http://codewall.blogspot.com/2011/03/upload-image-in-folder-in-php-step-by.html

 

The prob with your form is that if it worked anyone could upload a diffrent file other than an image which leaves you open to problems with attacks from out side users. You need to make sure you can varify that the file been uploaded is indeed an image.

I finally get it working. The problem is the path..

 

Just a simple question guys..

 

 

right now I'm using php function "copy" , is it the same as "move_uploaded_file" ?

 

Is it fine to use it? or will I'm going to have a problem latter on?

 

Which do guys prefer?

 

Anyone?

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.