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"

Recommended Answers

All 16 Replies

Does the user/ folder and it's sub-folders have write permissions?

the permissions in filezilla are 0755 for the folders

Member Avatar for diafol
 $location = '/user/'.$_SESSION['Username'].'/';

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

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

but how to move it into the same page with the script?

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"

Do both folders exist?

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

If it doesn't exist you have to create it first. See is_dir and mkdir.

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

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

not working

when i try

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

nothing is displayed

well i get an echo of $tmp_name after the function is called

i solve it with

dirname(__FILE__)
<?php 

    if(isset($_POST['upload-img']))
    {

        $img=$_FILES['image']['name'];
        $img_loc=$_FILES['image']['tmp_name'];
        $file_type=$_FILES['image']['type'];
        $img_folder="images/".$img_loc;

        if(move_uploaded_file($img_loc,$img_folder.$img))
        {

          ?>

          <script>alert("file successfully saved ! ")</script>

          <?php
        }
        else
        {
          ?>

            <script>alert("file not saved ! ")</script>

            <?php

        }

    }

?>

<html>

<body>

<form name="form1"  method="post" enctype="multipart/form-data">
<input type="file" name="image">
<button type="submit" name="upload-img">Click</button>
</form>

</body>

</html>

want to select an image from download or any other folder and want to save it in images folder which I have created in desktop..but this code doesn't work..all I can find from net is this..please help.

after selecting and submiting the image it doesn't save into the images folder.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.