2015-08-28 127 views
0

我只是學習PHP的工作方式,並嘗試使用move_uploaded_file上傳文件。我寫的代碼看起來很完美,但最終它產生了一個警告信息。我給我的代碼圖像文件不上傳在php

<?php 

if(isset($_POST['create'])){ 
$productcatid=$_POST['productcategory']; 

$name = ucfirst(trim($_POST['itemname'])); 
if(isset($_POST['status'])){ 
$status = true; 
} 
else{ 
$status = false; 
} 
if(isset($_POST['availability'])){ 
$avalability = true; 
} 
else{ 
$avalability = false; 
} 


$c=$_POST['price']; 
$d=$_POST['type']; 
$e=$_POST['brandname']; 
$f=$_POST['datecreated']; 
$g=$_POST['size']; 
$h=$_POST['colour']; 
$i=$_POST['fabric']; 


if(isset($_FILES['upload'])){ 
    $file = $_FILES['upload']; 
    $n = $file['name']; 
    $s = $file['size']; 
    $tm = $file['tmp_name']; 
    $er = $file['error']; 
    $target = 'uploadedfiles/'.$n; 

    if(move_uploaded_file($tm, $target)){ 
     $sql = "insert into product_items(item_name, is_active, category_id, image_url, date_created, is_item_available, type, brand_name, fabric, size, colour,price) "; 
     $sql .= " values('".$name."','".$status."','".$productcatid."','".$upload."','".$f."','".$avalability."','".$d."','".$e."','".$i."','".$g."','".$h."','".$c."')"; 
     include('config.php'); 
     $res = mysql_query($sql); 
     if($res){ 
      //header('Location:allproductitemcategory.php'); 
      echo 'success'; 
     } 
     else{ 
      echo mysql_error(); 
     } 
    } 
    else{ 
     echo 'error uploading file. '.$er; 
    } 
} 


} 
else{ 
    echo 'error'; 
} 
?> 

這是給下面的警告

警告:move_uploaded_file(uploadedfiles/s3.jpg)未能打開流:權限在/Applications/XAMPP/xamppfiles/htdocs/onlineshopping/insertproductitems.php否認線38

警告:move_uploaded_file():無法移動'/Applications/XAMPP/xamppfiles/temp/php6TeZrH''uploadedfiles/s3.jpg'/Applications/XAMPP/xamppfiles/htdocs/onlineshopping/insertproductitems.php上線38 錯誤上傳文件。 0

我只是卡在這裏,因爲我無法得到它。請幫助

+1

http://stackoverflow.com/questions/8103860/move-uploaded-file-gives-failed-to-open-stream-permission-denied-error-after – DannyPhantom

+0

thankx很多先生 –

回答

0

如果您的問題是關於權限只是chmod(更改模式)您的文件夾。 chmod(「yourfolder」,「r」);

+0

我剛剛改變了權限放置圖像的文件夾以及要上傳的位置 –