上传文件映像到服务器失败
问题描述:
我想要做的是当管理员试图创建一个新的产品上传到服务器的图像,因为它的名称是产品id.jpg。我搜索谷歌没有结果。代码似乎是正确的。有人能帮助我吗?我使用灯作为本地测试服务器。上传文件映像到服务器失败
<?php
// Parse the form data and add inventory item to the system
if (isset($_POST['product_name'])) {
$product_name = mysql_real_escape_string($_POST['product_name']);
$price = mysql_real_escape_string($_POST['price']);
$details = mysql_real_escape_string($_POST['details']);
$category = mysql_real_escape_string($_POST['category_choice']);
$condition= mysql_real_escape_string($_POST['condition']);
$supplier_choice= mysql_real_escape_string($_POST['supplier_choice']);
$handling_time= mysql_real_escape_string($_POST['handling_time']);
$weight= mysql_real_escape_string($_POST['weight']);
$information_box= $_POST['information'];
$pid = mysql_insert_id();
// Place image in the folder
$newname = "$pid.jpg";
move_uploaded_file($_FILES['my_photo']['tmp_name'], "../inventory_images/$newname");
header("location: products.php");
exit();
}
?>
<form action="add_product.php" enctype="multipart/form-data" name="my_Form" id="my_Form" method="post">
<tr>
<td>Φωτογραφία</td>
<td>
<label>
<input type="file" name="my_photo" id="my_photo"/>
</label>
</td>
</tr>
<tr>
<td> </td>
<td>
<label>
<input type="submit" name="button" id="button" value="Αποθήκευση" />
</label>
</td>
</tr>
</table>
</form>
答
正如您所说,您正在使用灯泡,请检查您上传文件的目录的权限。另外,还要检查目标路径中提到的所有文件夹的权限。
上传文件的目录和路径中的所有目录必须具有写权限。
如果move_uploaded_file不起作用,则尝试复制功能。 同时检查您上传的路径是否正确。
答
我认为你将有更好的运气得到的答案,如果你瘦不下来的代码只包含那些与问题相关的部分。这样做后,你可能会看到自己问题的答案。
例如,文件是否成功上传?如果没有,那么mysql_xxx代码和大部分表单都与您的问题无关。
你给你的脚本写权限到你的图像将被移动的文件夹? – ppp
如果有人上传一个php文件,当你非常小心地使用mysql_real_escape_string时,你不关心吗? var_dump($ _ FILES ['my_photo'] ['error'])'说什么? –
我怎么能在我的PHP权限给文件夹? – JimmyV