I want to make a simple picture uploader.
I have two pages 'index.html' and 'upload.php'
Here is the code for index.html
<html>
<head>
<script>
$(document).ready(function(){
$("#im").click(function() {
$("input[id='my_file']").click();
});
$("#su").click(function() {
$("input[id='submit']").click();
});
});
</script>
</head>
<body>
<form method="post" action="upload.php" >
<img id="im" src="pic.png" width="30" height="30" />
<img id="su" src="sent.png" width="50" height="50" />
<input type="file" id="my_file" style="display: none;" name="img" />
<input type="submit" id="submit" style="display: none;" value="Upload Image" name="submit"/>
</form>
Here is the code for upload.php:
<?php
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['img']['name']);
if(move_uploaded_file($_FILES['img']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['img']['name']).
" has been uploaded";
} else{
echo "fail : ". $_FILES['img']['error'] ;
}
?>
Also I created the dir uploads and I checked if it is writable and it is . I edited the php.ini and turned on the upload and raised the max size to 50m
When I upload a file it dispay : "fail : "
Aucun commentaire:
Enregistrer un commentaire