我不想嘗試捕獲文件和數據並上傳到php文件。我不確定我做錯了什麼,如果有人可以看到我做錯了請。這將上傳文件/圖片沒有問題,但是當我添加一個文本輸入後它不會工作,這是我一直在使用什麼作爲模板來審判html提交文件和文本數據到php
<iframe name="my_iframe" src="" id="my_iframe"></iframe>
<form action="http://www.********/upload11.php" method="post" enctype="multipart/form-data" target="my_iframe">
<input type="file" input id="input" name="image" />
<input type="text" name="Description" value="Image of Time"/>
<div>
<input type="submit" value="Send">
</div>
</form>
upload11.php
<?php
$upload_image = $_FILES["image"][ "name" ];
$folder = "images/";
move_uploaded_file($_FILES["image"]["tmp_name"], "$folder".$_FILES["image"]["name"]);;
$file = 'images/'.$_FILES["image"]["name"];
$uploadimage = $folder.$_FILES["image"]["name"];
$newname = $_FILES["image"]["name"];
$resize_image = $folder.$newname;
list($width,$height) = getimagesize($uploadimage);
$newwidth = 550;
$newheight = 350;
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($resize_image);
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, $resize_image, 100);
$out_image=addslashes(file_get_contents($resize_image));
$msg = '';
if($_SERVER['REQUEST_METHOD']=='POST'){
$a = ('" alt="" />');
$b = ("'<img src=\"\https://www.******/images/".$_FILES['image']['name']."$a'");
$Description = $_POST['Description'];
$image = $_FILES['image']['tmp_name'];
$img = file_get_contents($image);
$con = mysqli_connect('***','******','******','********');
$sql = "INSERT INTO links (hyper_links, link) VALUES ($b, $Description)";
$stmt = mysqli_prepare($con,$sql);
mysqli_stmt_bind_param($stmt, "s",$img);
mysqli_stmt_execute($stmt);
$check = mysqli_stmt_affected_rows($stmt);
if($check==1){
$msg = 'Successfullly UPloaded';
}else{
$msg = 'Could not upload';
}
mysqli_close($con);
}
?>
<?php
echo $msg;
?>
請在上傳圖片時添加** error_reporting(E_ALL); **以檢查錯誤。 – Sunny
我確實添加到我的php文件中,但是當我提交時,我只是得到了無法上傳 – INOH
我建議你看看我在這裏回答這個問題:[Full Secure Image Upload Script](http://stackoverflow.com/questions/38509334/full-secure-image-upload-script/38712921#38712921)它會教你很多關於上傳腳本和安全性的知識,以及在最後給你一個完整的工作腳本。您可以輕鬆地將文本字段添加到表單中,並使用PHP進行處理。這應該不是問題。 – icecub