0

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?

3
Contributors
4
Replies
7
Views
4 Years
Discussion Span
Last Post by dancks
0

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?

0

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.

0

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__) 
0

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.

Edited by dancks

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.