0

I have an image uploading script In upload form page there is an input field as shown below:

Part of the php script handling image upload is:

$path_parts = pathinfo($_FILES['product_image']['name']);
$imgext = $path_parts['extension'] ;

$imgextension = "." . $imgext ; //

// copying files to server
$target = "targetdomainpath/products/";
$target = $target . $_POST['product_name'].$imgextension;

//copying image
if(move_uploaded_file($_FILES['product_image']['tmp_name'], $target)) {
    //Tells you if its all ok
    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and information has been modified inside the directory";
} else {
    //Gives and error if its not
    echo "Sorry, there was a problem uploading your file. or you didnt select photo from the computer";
}
// end image copying

My problem is file is not uploading. Could you please help me

user229044
  • 232,980
  • 40
  • 330
  • 338
user1010966
  • 473
  • 1
  • 6
  • 13
  • Please can you post the HTML for the form that you're submitting from. Also are any of your error messages appearing? – Luke Nov 03 '11 at 14:07
  • You mean you get "Sorry, there was a problem" or just the file isn't there? Did you check folder exists and has the right permissions? Also, where does `$_FILES['uploadedfile']` come from? shoulnd' t it be `$_FILES['product_image']` ? – Damien Pirsy Nov 03 '11 at 14:07
  • 3
    As a bit of constructive criticism, please don't comment your code this way. Your comments aren't helpful, they simply state what each line already states in code. You should explain *why* something is doing what it does, not how it does it. – user229044 Nov 03 '11 at 14:09
  • Sorry I missed input fields. 1) input type "file" name "product_image" 2) input type "text" name "product_name". The said Folder exists here and has right permission (777). – user1010966 Nov 03 '11 at 14:10
  • 2
    Have you put `enctype="multipart/form-data"` in your
    tag?
    – Luke Nov 03 '11 at 14:11
  • Oh! I missed (enctype="multipart/form-data") in form tag. Thank you Coulton – user1010966 Nov 03 '11 at 14:20
  • @meagar, once I was working on some code where I found the following: `int v1; //this is a variable` – Mikhail Nov 03 '11 at 14:25

1 Answers1

1

Perform a var_dump on $_FILES and if it's empty you're probably not submitting your form correctly.

Forms that include files must contain a enctype="multipart/form-data"

Good luck!

Mikhail
  • 8,692
  • 8
  • 56
  • 82