0

I am trying to insert an image in one folder, but I guess i am not doing it correctly, can someone correct my code?

//Place the image in the folder  
$newname = "$menu_name-01.jpg";    
move_uploaded_file($_FILES['fileField']['tmp_name'],"/product_images/$brand/$newname");

Where,

$menu_name = trim(mysql_prep($_POST['menu_name']));  
$brand = trim(mysql_prep($_POST['brand']));
5
  • $menu_name-01.jpg is not a valid variable name. They cannot have "." in it and numerics. So "$nename" is probably NULL or FALSE. var_dump that so see whats going on. Commented Aug 9, 2014 at 17:15
  • Nope, still it is not inserting image Commented Aug 9, 2014 at 17:15
  • Also I'd suggest you to enable error mode, so you would've seen this during development. Commented Aug 9, 2014 at 17:16
  • are you sure your file is uploading correctly? if you are sure the file is uploading, then check for destination directory permissions (if you are using unix OS) Commented Aug 9, 2014 at 17:19
  • No, I am using Windows. I think the fault is in the destination path only. I will check it. Commented Aug 9, 2014 at 17:22

1 Answer 1

1

You should change:

$newname = "$menu_name-01.jpg";

to

$newname = $menu_name.'-01.jpg';

Because its looking for the variable as a whole ($menu_name-01.jpg) instead of concatenating $menu_name variable with -01.jpg.

Sign up to request clarification or add additional context in comments.

3 Comments

Its still not working, but your answer is very much beneficial. This was a mistake, but it is still not inserting the image in the specified folder. What is your suggestion?
@MrTree You're wrong. He used double quotes so PHP replaced $menu_name with the assigned value.
@CharlotteDunois No, it would take $menu_name-01 as a variable, but there is no $menu_name-01 variable, only $menu_name, the intention was to concatenate $menu_name and -01.jpg, you would either have to have a space in-between $menu_name and -01.jpg or join the string to the variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.