Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP图片上传信息编辑_Php_Image_Forms_Upload - Fatal编程技术网

PHP图片上传信息编辑

PHP图片上传信息编辑,php,image,forms,upload,Php,Image,Forms,Upload,我有一个表单,允许我编辑数据库中的数据。我需要 提交表单后,将图像上载到文件夹。这是一个编辑页面,我设置它的方式是从数据库调用图像名称,图像存储在文件夹中。有人能帮我吗 <?php // if there are any errors, display them if ($error != '') { echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div&

我有一个表单,允许我编辑数据库中的数据。我需要 提交表单后,将图像上载到文件夹。这是一个编辑页面,我设置它的方式是从数据库调用图像名称,图像存储在文件夹中。有人能帮我吗

<?php 
 // if there are any errors, display them
 if ($error != '')
 {
 echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
 }
 ?> 

 <form action="" method="post">
 <input type="hidden" name="id" value="<?php echo $id; ?>"/>
 <div>
 <p><strong>ID:</strong> <?php echo $id; ?></p>
 <label> Job Name:</label><br><br>
 <input type="text" name="job_name" value="<?php echo $name; ?>"/><br/>
 <label></label><br><br>
 <label>Job Thumbnail:</label><br><br>
 <input id="upload"  name="file" type="file" size="10"><br><br>
 <input id="filename" type="text" name="job_timg" placeholder="This Fills Automatcially" value="<?php echo $timg; ?>"/><br/>
 <label> Job Name:</label><br><br>
 <input type="submit" name="submit" value="Submit">
 </div>
 </form> 
 </body>
 </html> 
 <?php
 }

// connect to the database
 include('connect.php');

 // check if the form has been submitted. If it has, process the form and save it to the database
 if (isset($_POST['submit']))
 { 
 // $_FILES["file"]["error"] is HTTP File Upload variables $_FILES["file"] "file" is the name of input field you have in form tag.

 // confirm that the 'id' value is a valid integer before getting the form data
 if (is_numeric($_POST['id']))
 {
 // get form data, making sure it is valid
 $id = $_POST['id'];
 $name = mysql_real_escape_string(htmlspecialchars($_POST['job_name']));
 $timg = mysql_real_escape_string(htmlspecialchars($_POST['job_timg']));

 // check that name/image fields are both filled in
 if ($name == '' || $timg == '')
 {
 // generate error message
 $error = 'ERROR: Please fill in all required fields!';

 //error, display form
 renderForm($id, $name, $timg, $error);
 }
 else
 {
 // save the data to the database
 mysql_query("UPDATE tbl_job SET job_name='$name', job_timg='$timg' WHERE job_id='$id'")
 or die(mysql_error()); 


 // once saved, redirect back to the view page
 header("Location: gallery_edit.php"); 
 }
 }
 else
 {
 // if the 'id' isn't valid, display an error
 echo 'Error!';
 }
 }


 else
 // if the form hasn't been submitted, get the data from the db and display the form
 {

 // get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0)
 if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0)
 {
 // query db
 $id = $_GET['id'];
 $result = mysql_query("SELECT * FROM tbl_job WHERE job_id=$id")
 or die(mysql_error()); 
 $row = mysql_fetch_array($result);

 // check that the 'id' matches up with a row in the databse
 if($row)
 {

 // get data from db
 $name = $row['job_name'];
 $timg = $row['job_timg'];

 // show form
 renderForm($id, $name, $timg, '');
 }
 else
 // if no match, display result
 {
 echo "No results!";
 }
 }
 else
 // if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error
 {
 echo 'Error!';
 }


 }






?>


处理文件时,表单必须包含有效的enctype

<form action="" method="post" enctype="multipart/form-data">

有关处理文件的详细信息,请访问PHP.net上的以下页面:


处理文件需要在表单标记中使用有效的enctype欢迎您,康纳。为了结束这个问题,我决定在下面贴一个答案,你可以接受它。这样,它还会告诉其他人找到了解决方案。此外,在接受答案时,它会增加你的代表分数。方法如下:然后对我下面的答案做同样的操作。我不是为了得分,而是为了向您展示堆栈系统是如何工作的。欢迎来到Stack。