0
votes

i'm trying to set up my site so that I can use a mobile device to upload an image. However whenever I attempt to upload the image it doesn't work and throws out two errors:

Warning: move_uploaded_file(UPLOADS/Image Attachment 27/03/16.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home3/hutch/public_html/stencylcollins/upload1.php on line 29

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpSZy8LW' to 'UPLOADS/Image Attachment 27/03/16.jpg' in /home3/hutch/public_html/stencylcollins/upload1.php on line 29

And after this I get my echo

UPLOAD SUCCESSFUL: Your document has now been uploaded and is ready to send.

Anyone know what's going on here?

<?php
    //login 
    ob_clean();session_start();

    if (isset($_GET['logout'])){
    session_destroy();  
    }

    if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] == false) {
        header("Location: index.php");
    }

    //timezone 

    date_default_timezone_set('Europe/London');
    $date = date('d/m/y', time());

    //upload 
    if(isset($_FILES['UploadFileField'])){
        $allowed = array('jpg','png','jpeg');
        $name = $_FILES["UploadFileField"]["name"];
        $tmp = $_FILES['UploadFileField']['tmp_name'];
        $type = $_FILES['UploadFileField']['type'];
        $newName = "Image Attachment ".$date.".jpg";
        $types = array('jpg','png','jpeg');
        $ext = pathinfo($name, PATHINFO_EXTENSION);

        if(in_array($ext,$types)){
            move_uploaded_file($tmp, "UPLOADS/$newName");
            echo '<font color="#006600" size="3"><p align="center"><b>UPLOAD SUCCESSFUL: </font><font color="#000000" size="3">Your document has now been uploaded and is ready to send.</b></p></font>';
        } 

        else {
            if(!$tmp){
                echo '<font color="#FF0000" size="3"><p align="center"><b>UPLOAD FAILED: </font><font color="#000000" size="3">No document has been selected.</b></p></font>';
            }

            else {
                echo '<font color="#FF0000" size="3"><p align="center"><b>UPLOAD FAILED: </font><font color="#000000" size="3">Uploaded document was an incorrect extension type, please use ".jpg", ".jpeg", or "png" only.</b></p></font>';
            }
        }
    }
?>
2
Hard to say for sure without knowing what the HTML form looks like. Plus, if on a * NIX server, UPLOADS isn't the same as uploads. Plus, I see a GET array, so make sure the form isn't using GET as opposed to POST including a valid enctype.Funk Forty Niner
You've been given an "answer" below. I'll let you take it up with him. Whether or not it's a "solution", is beyond me.Funk Forty Niner

2 Answers

1
votes

You can't have slashes in a file name. The file name Image Attachment 27/03/16.jpg is totally invalid because you are actually referring to a file called 16.jpg in the folder 03 which is itself in Image Attachment 27. None of these directories exist, hence your error.

-2
votes

Filename with spaces??? i think this is a bad way.

 // $newName = "Image Attachment ".$date.".jpg"; ???
 $newName = "Image_Attachment_".$date.".jpg";

// you can check where you trying to upload a file
if(is_dir("UPLOADS/")) { echo "dir ok";} else { echo "dir not ok"; }

and in your code you dont need use time() into date function, because date() without second parameter returns current date :)