0

我很难让这个工作,我还没有想出一个工作场景。基本上,这是一个简单的用户友好的管理员,应该上传图像。但是,我无法让上传工作。文件名被添加到数据库中就好了,但图像不会上传。

这是代码:

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 />";
}

感谢您的关注,并提前感谢您为我指明了正确的方向!

4

2 回答 2

2

SITE_ROOT需要是本地目录,即“ C:\...”或“ /home/...”,不能是URL结构。将其更改为应上传文件的本地目录,检查权限,您应该一切顺利。

于 2012-04-16T14:19:52.487 回答
0

我这样使用它:

   if(!is_dir($dir = $_SERVER['DOCUMENT_ROOT']."/fies_path"))mkdir($dir);
    move_uploaded_file($_FILES['file']['tmp_name'],$src = $dir."/$file_name.ext");
于 2012-04-16T14:24:35.597 回答