I'm stucked in one place, I have a file upload php file but when I want to upload the image I have errors called:
"Warning: move_uploaded_file(): failed to open stream: No such file or directory.." and
"Warning: move_uploaded_file(): Unable to move 'C:\wamp\tmp\php7E6D.tmp' to 'site/images/UBI30_Giveaway_box_CARDS_1.jpg'.. "
My Upload php looks like this:
//Image datas
$target_dir = "site/images/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Submint button pressed?
if(isset($_POST['submit'])){
$nev=$_POST['nev'];
$about=$_POST['about'];
$image=$_FILES["fileToUpload"]["name"];
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
// Does it image?
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
//Recently the image is uploaded?
if (file_exists($target_file)) {
echo "Sajnáljuk, ez már egy feltöltött fájl..";
$uploadOk = 0;
}
//If everything okay, upload.
if ($uploadOk == 0) {
echo "Sajnáljuk a kép nem került feltöltésre..";
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "A ". basename( $_FILES["fileToUpload"]["name"]). " feltöltve.";
} else {
echo "Sajnáljuk, hiba történt a kép feltöltése közben.";
}
}
}
// Upload datas to db.
$stmt = $db->prepare("INSERT INTO `jelolt`(`name`, `about`, `image`) VALUES ('$nev','$about','$image')");
$stmt->execute();
// A lekérdezés helyes futásának ellenörzése.
if (!$stmt) {
print_r($db->errorInfo());
}
I hope you guys can be clever than me, I'm just don't find my bug around 3 hours ago.
UPDATE with $target_dir = getcwd();
modify this start work but not put the correct folder, and if I change the url I got the same problem . I need to attach /views/site/image url after getcwd() but of corse it's doesn't work for me: $target_dir = getcwd()."views/site/image";