addproduct.php snippet (there are lots of other inputs, not sure if that matters):

<form method="POST" action="add.php" enctype="multipart/form-data">
<p>Picture:<input type="file" id="pic_upload" name="pic" />
<input type="submit" />
</form>

add.php:

    if(isset($_FILES["pic"]))
    {
        if($_FILES["pic"]["error"]==0)
        {
            $name = explode(".",basename($_FILES["pic"]["name"]));
            $target = realpath(dirname($_SERVER['PHP_SELF']))."/images/".$name[0].session_id().".".$name[1];
            $temp = $name[0].session_id().".".$name[1];
            if(!move_uploaded_file($_FILES["pic"]["tmp_name"],$target))
            {
                add_error("Picture specified did not upload");
            }
            $_POST['pic']=$temp;
        }
        else
        {
            add_error("Picture specified did not upload correctly");
        }
    }

error:

Warning: move_uploaded_file(/images/Adult_Bobcatb6b8d5749abe65888cfa89200da5bdb4.jpg): failed to open stream: No such file or directory in /u/students/j/j.d.dancks/public_html/onestopshop/add.php on line 52

Warning: move_uploaded_file(): Unable to move '/tmp/phpiRN9EP' to '/images/Adult_Bobcatb6b8d5749abe65888cfa89200da5bdb4.jpg' in /u/students/j/j.d.dancks/public_html/onestopshop/add.php on line 52

Warning: Cannot modify header information - headers already sent by (output started at /u/students/j/j.d.dancks/public_html/onestopshop/add.php:52) in /u/students/j/j.d.dancks/public_html/onestopshop/add.php on line 148

Any ideas what I did wrong?

Recommended Answers

All 4 Replies

Your first error seems like that the directory you are trying to use does not exists on the server. This can cause error two to happen.

As for your third error, did you use header("Location: ...") somewhere else in your code?

Yes, the header at the end is supposed to send the user's browser back to where they were before, and since php printed to the screen its gonna throw that error. No surprise there. As for the first 2, I'm using the school server and other people I believe are trying to do this now, or if not its certainly happened in the past. I've never done this before so I wasn't sure what I'm doing here. I can see that a file is stored in some folder on the server with a reference to it saved in php until I do something with it. I just don't know what to look for.

hi,

can you echo this in the same directory as your script and one in the image directory. Whatever comes up, that is your working directory and the image directory .

    basename(__DIR__) 

that code wouldn't work so I did basename(dirname(__FILE__)) (why do I need to escape???) It prints onestopshop and images, accordingly. But I knew that. so images is a subdirectory in onestopshop. All of my pages are in onestopshop.

oohhh I see I need to append real_path(dirname(__FILE__))

yeah that worked.

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.