This code does not print the temporary name of the uploaded image as well does not upload any picture in my Photo folder. but print image name. it work others computer correctly . where is the problem? please help me. i am using php Version 5.6.20
<!DOCTYPE html>
<html>
<head>
<title>Image Upload</title>
</head>
<body>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$destination = "Photo/".$_FILES['image']['name'];
$filename = $_FILES['image']['tmp_name'];
echo $destination;
echo "<br/>";
echo $filename;
echo "<br/>";
if (file_exists($destination))
echo "Sorry, file already exists.";
else
move_uploaded_file($filename, $destination);
$name=$_FILES['image']['name'];
$tmp_name=$_FILES['image']['tmp_name'];
echo $tmp_name;
}
?>
<form method="POST" enctype="multipart/form-data">
<table>
<tr>
<td>Choose Image</td>
<td><input type="file" name="image"/> </td>
</tr>
<tr>
<td>Description:</td>
<td><textarea name="Description" rows="4" cols="40"/></textarea></td>
</tr>
<tr>
<td></td>
<td> <input type="submit" name="submit_image" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Image Upload</title>
</head>
<body>
<?php
if(isset($_POST['submit_image']))
{
$destination = "Photo/".$_FILES['image']['name'];
$filename = $_FILES['image']['tmp_name'];
echo $destination;
echo "<br/>";
echo $filename;
echo "<br/>";
if (file_exists($destination))
echo "Sorry, file already exists.";
else
move_uploaded_file($filename, $destination);
$name=$_FILES['image']['name'];
$tmp_name=$_FILES['image']['tmp_name'];
echo $tmp_name;
}
?>
<form method="POST" enctype="multipart/form-data">
<table>
<tr>
<td>Choose Image</td>
<td><input type="file" name="image"/> </td>
</tr>
<tr>
<td>Description:</td>
<td><textarea name="Description" rows="4" cols="40"/></textarea></td>
</tr>
<tr>
<td></td>
<td> <input type="submit" name="submit_image" value="Submit"></td>
</tr>
</table>
</form>
</body>
</html>
I tried this code it is working for me. please give read write permission of your photo folder I think it will work for you.
your code is working fine , check with 'Photo/' folder permission and tmp folder path too. ex : D:\\xampp\\tmp\\phpDCD9.tmp.
Your code is perfectly working on my machine. I think you might want to check the directory name Photo
to which the uploaded files are been stored. check your destination folder name inn your coding and defined folder name where your project is present are same. Kindly post your error
or warning
message so that it is easy to help.
i think this part write properly like this it will solve
if (file_exists($destination)){
echo "Sorry, file already exists.";
}else{
move_uploaded_file($filename, $destination);
$name=$_FILES['image']['name'];
$tmp_name=$_FILES['image']['tmp_name'];
echo $tmp_name;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.