i've done many things on fileupload project but there are problem that make the project stop when i upload image it don't give any problems or any errors but the image that get uploaded don't show in the '/uploads folder
the code that i use
<html>
<head>
<title>image uploader</title>
</head>
<body>
<form action="upload.php" method="POST" enctype="multipart/form-data">
image selector :
<input type="file" name="uploadsrc" /> <input type="submit" value="Upload">
</form>
<style type="text/css">
body{;
font-family: sans-serif;
}
<?php
//connected to database
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("meinimages") or die(mysql_error());
$uploads_dir = '/uploads';
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
// basename() may prevent filesystem traversal attacks;
// further validation/sanitation of the filename may be appropriate
$name = basename($_FILES["pictures"]["name"][$key]);
move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
}
?>
<?php
// file properties
@$file = $_FILES['image']['tmp_name'];
if (!isset($file))
echo "please select an image.";
else
{
$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);
if ($image_size==FALSE)
echo "you try upload nonimage.";
else
{
if (!$insert = mysql_query("INSERT INTO store VALUES ('','$image_name','$image')"))
echo "problem while upload the $image.";
else
{
$lastid = mysql_insert_id();
echo "image is uploaded.<p />your image:<p /><img src=get.php?id=$lastid>";
}
}
}
ps : is this an error on my code or error on the database/phpmyadmin ?
$_FILES["pictures"]? The form field is calleduploadsrcnotpicturesmysqlclass so if you are using PHP 7+ then the db calls will fail as themysqlroutines are no longer part of php. Usemysqliinstead so you can utilise prepared statements. The code suggests multiple files but the form element allows only a single due to the lack ofmultipleattribute