How To Save An Uploaded File On Localhost?
I have been using to upload an image file from HTML5/JS and using PHP script to save it in localhost(/var/www/) but i cant save it. the function move_uploaded_file always returns f
Solution 1:
Try
move_uploaded_file($_FILES['image_file']['tmp_name'], $target.$_FILES['image_file']['name'])
Because you need to specify the name of file, not only the directory.
See example from PHP documentation
<?php
$uploads_dir = '/uploads';
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name = $_FILES["pictures"]["name"][$key];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
}
?>
Solution 2:
try this
if(is_uploaded_file($_FILES['image_file']['tmp_name']))
{
move_uploaded_file($_FILES['image_file']['tmp_name'], $target.$_FILES['image_file']['name']);
echo "The file ". basename( $_FILES['image_file']['name']). " has been uploaded...";
}
Post a Comment for "How To Save An Uploaded File On Localhost?"