2
votes

I get this two messages while I try to upload an image:

Warning: move_uploaded_file(/images/uploads/2014-02-28_17:39:37-Untitled-1.png) [function.move-uploaded-file]: failed to open stream: Invalid argument in D:\AppServ\www\my\addpost.php on line 23

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Windows\Temp\php13A7.tmp' to '/images/uploads/2014-02-28_17:39:37-Untitled-1.png' in D:\AppServ\www\my\addpost.php on line 23

this is my code:

$name = date("Y-m-d_H:i:s").'-'.$_FILES['image']['name'];
$type = $_FILES['image']['type'];
$temp = $_FILES['image']['tmp_name'];
$uerror = $_FILES['image']['error'];

list($width, $height) = @getimagesize($_FILES['image']['tmp_name']);
$maxhight = 1;
$maxwidth = 1;
if ($error == 0) {
    if(($height > $maxhight) or ($width > $maxwidth)){
        move_uploaded_file($temp,"/images/uploads/".$name);
    }else{
       $error = "Just you can upload photos!!";
    }
}else {
    $error = "error while uploading : " . $uerror;
}

note :

/images/uploads/

folder is already exist

1

1 Answers

5
votes

You using : in directory name. Try change your directory name:

$name = date("Y-m-d_H:i:s").'-'.$_FILES['image']['name'];

into this:

$name = date("Y-m-d_H-i-s").'-'.$_FILES['image']['name'];