Cle*_*anX 3 javascript php file-upload image-uploading
每次我尝试上传文件时都会收到以下错误.
"警告:文件上传错误 - 无法在第0行的"未知"中创建临时文件
这是我的HTML表单,
<form action="./inventory_list.php" enctype="multipart/form-data" name="myForm" id="myForm" method="post">
<table width="625" border="1" cellpadding="5">
<tr>
<td width="84">Product Name</td>
<td width="399"><input type="text" name="product_name" id="product_name"></td>
</tr>
<tr>
<td>Product Price</td>
<td><label for="textfield2">Rs:</label>
<input type="text" name="price" id="price"></td>
</tr>
<tr>
<td>Category</td>
<td><select name="category" id="category">
<option value="" selected="selected"></option>
<option value="Bedroom ">Bedroom </option>
<option value="Living">Living room</option>
<option value="Dining">Dining</option>
</select></td>
</tr>
<tr>
<td>Sub - Category</td>
<td><select name="subcategory" id="subcategory">
<option value="" selected="selected"></option>
<option value="dinet">Dining tables</option>
<option value="shoe">shoe racks</option>
<option value="wardrobe">wardrobes</option>
<option value="sofa">sofa</option>
</select></td>
</tr>
<tr>
<td>Product Details</td>
<td><textarea name="details" cols="50" rows="10" id="details"></textarea></td>
</tr>
<tr>
<td>Product Image</td>
<td><label>
<input type="file" name="fileField" id="fileField"/>
</label></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="button" id="button" value="Add this Item now"></td>
</tr>
</table>
</br>
</form>
Run Code Online (Sandbox Code Playgroud)
这是我的PHP代码,
if(isset($_POST["product_name"]))
{
$product_name = mysql_real_escape_string($_POST["product_name"]);
$price= mysql_real_escape_string($_POST["price"]);
$category= mysql_real_escape_string($_POST["category"]);
$subcategory= mysql_real_escape_string($_POST["subcategory"]);
$details= mysql_real_escape_string($_POST["details"]);
//see if duplicate product exists
$sql = mysql_query("select id from products where product_name='$product_name' limit 1");
$product_match = mysql_num_rows($sql); //count the output
if($product_match>0)
{
echo "The product name already exists";
exit();
}
$sql= mysql_query("INSERT INTO `mystore`.`products` (`product_name`, `price`, `details`, `category`, `subcategory`, `date_added`) VALUES ( '$product_name', '$price', '$details', '$category', '$subcategory', now());")or die(mysql_error());
$pid = mysql_insert_id();
$newname = "$pid.jpg";
move_uploaded_file($_FILES['fileField']['tmp_name'],'../inventory_images/$newname');
}
Run Code Online (Sandbox Code Playgroud)
我试图在localhost上传,测试服务器:XAMPP,操作系统:MAC 10.8
很长一段时间我坚持这个,我尝试了很多东西,但没有任何工作.
ziz*_*jab 11
在终端类型中:
chmod -R 777 /your/upload/folder
通过执行以下代码,您可以知道php上传文件的文件夹:
$tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir();
die($tmp_dir);
Run Code Online (Sandbox Code Playgroud)
在我的情况下/var/...,当我获得777许可时,我得到了这个,我没有得到任何错误.
编辑
设置777 /var是危险的,所以你必须将它设置为php上传文件的文件夹(你可以购买上面的代码).
您应该检查您的 php.ini 并查找“upload_tmp_dir”选项。默认为空。之后,检查您的 tmp 目录的权限。如果你想知道你的服务器正在使用什么upload_tmp_dir,你可以简单地使用这段代码
$tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir();
die($tmp_dir);
Run Code Online (Sandbox Code Playgroud)
最后在终端 shell 中,您可以键入:chmod -R 777 'your_tmp_upload_dir'