0

so i have

<?php
ob_start();
session_start();
?>
<form action="upload.php" method="post" enctype="multipart/form-data">
    <input type="file" name="file"><br><br>
    <input type="submit" value="Upload">
</form>

<?php
$file_name = $_FILES['file']['name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$tmp_name = $_FILES['file']['tmp_name'];
$error = $_FILES['file']['error'];

if (isset($file_name)) {
    if (!empty($file_name)) {
        $location = '/user/'.$_SESSION['Username'].'/';
        if (move_uploaded_file($tmp_name, $location.$file_name)) {
            echo 'Uploadat!';   
        }
    } else {
        echo 'Te rugam alege o imagine!';   
    }
}

?>

and is not working it says "Unable to move '/tmp/phppQNtB5' to '/user/axxxA/back_view.jpg' in /home/user/public_html/user/axxxA/upload.php on line 20"

3
Contributors
14
Replies
35
Views
3 Years
Discussion Span
Last Post by andreiviziru
0
 $location = '/user/'.$_SESSION['Username'].'/';

This will write to root/user/... probably not what you want.
Try:

 $location = 'user/'.$_SESSION['Username'].'/';
0

doesn't work with

$location = 'user/'.$_SESSION['Username'].'/';

it says "Warning: move_uploaded_file(user/axxxA/file.txt) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/user/public_html/user/axxxA/upload.php on line 20"
and "Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpomrzCU' to 'user/axxxA/file.txt' in /home/user/public_html/user/axxxA/upload.php on line 20"

0

the user exist the other one i can't check it i'm on a free host

Edited by andreiviziru

0

i did

<?php
if (is_dir($tmp_name = $_FILES['file']['tmp_name'])) {
    echo 'the temporary folder exists<br>';
} else {
    echo 'the temp folder doesn\'t exist<br>';
}

if (is_dir('/user'.$_SESSION['Username'])) {
        echo 'the temporary folder exists';
} else {
    echo 'the main folder doesn\'t exist';
}
?>

i get the negative answers
but for the second i know for sure it exists

Edited by andreiviziru

0

what if i define the location of the temp file or folder in my "public_html"

0

when i try

echo $tmp_name = $_FILES['file']['tmp_name'];

nothing is displayed

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.