NotJay
NotJay

Reputation: 4076

PHP: move_uploaded_file Issues. What's wrong here?

I am having a very difficult getting this working and I have yet to come up with a working scenario. Basically, this is a simple user-friendly admin which is supposed to upload an image. However, I can't get the upload to work. The filename is getting added to the database just fine but the image will not upload.

Here's the code as is:

function editMain($data){
  array_pop($data);
  $where = "main_id = {$data['main_id']}";
  unset($data['main_id']);
//upload image
if ($_FILES['main_picture']['size'] > 1){ //if image deal with it
  $data['main_picture'] = '/images/'.$_FILES['main_picture']['name'];
  $uploadedfile = $_FILES['main_picture']['tmp_name'];
  if (move_uploaded_file($uploadedfile, SITE_ROOT.$data['main_picture']))
  echo "successfully uploaded {$data['main_picture']}<br />";
  else 
  echo "failed to upload {$data['main_picture']}<br />";
}

Thanks for looking and thanks in advance for pointing me in the right direction!

Upvotes: 0

Views: 112

Answers (2)

user669677
user669677

Reputation:

I use it that way:

   if(!is_dir($dir = $_SERVER['DOCUMENT_ROOT']."/fies_path"))mkdir($dir);
    move_uploaded_file($_FILES['file']['tmp_name'],$src = $dir."/$file_name.ext");

Upvotes: 0

tcole
tcole

Reputation: 927

SITE_ROOT needs to be a local directory, ie "C:\..." or "/home/...", it cannot be a URL structure. Change that to the local directory of where the file should be uploaded, check permissions, and you should be good to go.

Upvotes: 2

Related Questions