如果他喜欢使用jquery ajax和PHP,我正在创建一个用户可以上传数据+图像的表单。到目前为止一切都在数据方面很好,但在图像上传PHP我有一个问题上传文件到正确的位置。查询工作正常,并将正确的数据提交到表中。你能帮我看一下图片上传吗?我尝试使用一些东西进行调试,但到目前为止一切看起来都是正确的。
这是我的php文件脚本:
if(isset($_POST['discussion_title'], $_POST['discussion_subjects'], $_POST['discussion_textarea'])) {
$user_id = (int)$_SESSION['user_id'];
$title = mysql_prep($_POST['discussion_title']);
$link = mysql_prep($_POST['discussion_link']);
$subject = mysql_prep($_POST['discussion_subjects']);
$discussion = mysql_prep($_POST['discussion_textarea']);
$discussion_timestamp = time();
if ($_FILES["discussion_image"]["name"] != "") {
$test = explode(".", $_FILES["discussion_image"]["name"]);
$extension = end($test);
$name = rand(100, 9999999999);
$file_temp = $_FILES['discussion_image']['tmp_name'];
$file_path = 'uploaded_pictures/uploads/' . $user_id . '/'. $name .'.'.$extension;
$file_path = mysqli_real_escape_string($connection, $file_path);
move_uploaded_file($file_temp, $file_path); // move_uploaded_file() is a built in function of PHP
$query = "INSERT INTO discussions_table (user_id, title, link, image_link, subject, discussion, discussion_timestamp) VALUES ($user_id, '$title', '$link', '$file_path', '$subject', '$discussion', $discussion_timestamp)";
//$save_path = "uploaded_pictures/uploads/" . $user_id ."/$user_id.png";
$save_path = 'uploaded_pictures/uploads/' . $user_id . '/'. $name.'.'.$extension;
$save_path_small = "uploaded_pictures/uploads/" . $user_id . "/" . $name.'small.'.$extension;
create_thumbnail($file_path, $save_path, 250, 250); // creates thumbnail for profile picture
create_thumbnail($file_path, $save_path_small, 50, 50); // creates thumbnail for small user picture
var_dump($_FILES['discussion_image']['tmp_name']);
} else {
$query = "INSERT INTO discussions_table (user_id, title, link, subject, discussion, discussion_timestamp) VALUES ($user_id, '$title', '$link', '$subject', '$discussion', $discussion_timestamp)";
}
$result = mysqli_query($connection, $query);
}
这里是alert()中给出的错误,因为我使用了var_dump
警告:move_uploaded_file(uploaded_pictures / uploads / 20 / 499297822.jpg)[function.move-uploaded-file]:无法打开流: D:\ wamp \中没有此类文件或目录www \ asserter \ widgets \ discussion_board_submit.php 在线 22
警告:move_uploaded_file()[function.move-uploaded-file]:无法移动&#39; D:\ wamp \ tmp \ php260.tmp&#39;到&#39; uploaded_pictures / uploads / 20 / 499297822.jpg&#39;在 D:\ wamp \ www \ asserter \ widgets \ discussion_board_submit.php 22 上<
警告:getimagesize(uploaded_pictures / uploads / 20 / 499297822.jpg)[function.getimagesize]:无法打开流: D:\ wamp \ www \ asserter \中没有此类文件或目录在 4 行上包含\ create_thumbnail.php
警告:getimagesize(uploaded_pictures / uploads / 20 / 499297822.jpg)[function.getimagesize]:无法打开流: D:\ wamp \ www \ asserter \中没有此类文件或目录在 4 行上包含\ create_thumbnail.php
string(22)&#34; D:\ wamp \ tmp \ php260.tmp&#34;
答案 0 :(得分:0)
答案 1 :(得分:0)
How to create directory in php? - 使用它来创建目录,我已在那里回答。它将帮助您为多用户创建目录。稍后您可以获得哪些用户上传了所有文件。
for error Undefined offset:在php中你应该使用isset()为1设置值 $ src_pos [1],$ new_size [0],$ new_size [1],$ size [0],$ size [1]