我創建了一個測試頁面,瞭解如何上傳圖片。我試圖將圖像保存到我創建的名爲image的文件夾中,然後在我的數據庫中存儲該圖像的文件名,以幫助處理空間。現在圖像文件名不存儲,而是字Array
正在存儲。我確實遇到了錯誤,以及其他錯誤。我點擊上傳後,我收到以下錯誤:困難創造圖片上傳選項
Warning: move_uploaded_file(image/picturetest.jpg): failed to open stream: No such file or directory in /home4/fdfsfs/public_html/example.com/img_test.php on line 34
Warning: move_uploaded_file(): Unable to move '/tmp/phpUg7p4D' to 'image/picturetest.jpg' in /home4/fdsfafa/public_html/example.com/img_test.php on line 34
There was an error!
**Notice: Array to string conversion in /home4/fdsfaf/public_html/example.com/img_test.php on line 59
34號線:
if (move_uploaded_file($tmp_name, $destinationFolder.$filename)) {
59號線:
$stmt->execute();
完整的腳本:
$filename = $_FILES['file']['name'];
//$filesize = $_FILES['file']['size'];
//$filetype = $_FILES['file']['type'];
$tmp_name = $_FILES['file']['tmp_name'];
$file_error = $_FILES['file']['error'];
if(isset($_POST['create'])){
$file = $filename;
$file = $_FILES['file'];
//$file = "productpics/". $_FILES['file']['name']; // save the filename
}else {
echo "error!";
}
if (isset($filename)) {
if (!empty($filename)) {
$destinationFolder = 'image/';
if (move_uploaded_file($tmp_name, $destinationFolder.$filename)) {
echo 'Uploaded!';
} else {
echo 'There was an error!';
}
} else {
echo 'Please choose a file.';
}
}
//Connection
$con = mysqli_connect("localhost","","","");
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
if ($stmt = mysqli_prepare($con, "INSERT INTO image (img) VALUES (?)")) {
/* bind parameters for markers */
$stmt->bind_param('s', $file);
/* execute query */
$stmt->execute();
//if(!$stmt->execute()){trigger_error("there was an error....".$con->error, E_USER_WARNING);}
/* close statement */
mysqli_stmt_close($stmt);
echo "Success!";
} else {
echo "Failed!";
}
$result = mysqli_query($con,"SELECT * FROM image");
if($row = mysqli_fetch_array($result)) {
if($row['img'] == ""){
echo "<img src='images/default_pic.png' alt='No Picture'>";
} else {
echo "<img src='images/".$row['img']."' alt='Profile Picture'>";
}
echo "<br><br><br><br>";
}
?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="file" class="inputbarfile">
<input type="submit" name="create" id="signinButton" value="Upload">
</form>
有誰看到我在做什麼錯這個???
在腳本的最頂部你寫的'$文件= $ _FILES [ '文件'];'這將是爲什麼你正在寫'Array'到數據庫這裏'$ stmt-> bind_param(「S」,$文件);' – Rasclatt
你會想這可能保存到數據庫:'$ destinationFolder $ filename' – Rasclatt
@Rasclatt我很困惑,你。正在說要做。 – Becky