Bom dia,
Estou a tentar fazer upload de imagens para uma pasta sem fazer refresh à página, para isso estou a usar javascript e ajax. Mas estou com uns erros..
Isto é a função que recebe o valor do fileup e manda o o ficheiro update.php .
Código (Javascript):
O ficheiro update.php é este:
Código (PHP):
Está-me a dar o seguinte erro: Warning: getimagesize() [function.getimagesize]: Filename cannot be empty inC:\xampp\htdocs\WebApps\ws_apps\ws_app3\article-details\update.php on line 45
A linha 45 é esta: list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']);
O que tenho que mandar no valor de $_FILES['fileup']['tmp_name'] ?
Estou a tentar fazer upload de imagens para uma pasta sem fazer refresh à página, para isso estou a usar javascript e ajax. Mas estou com uns erros..
Isto é a função que recebe o valor do fileup e manda o o ficheiro update.php .
Código (Javascript):
function update() {
var fileup = document.getElementById("fileup").value;
//alert(fileup);
$.post('update.php', { fileup: fileup }, function(resposta) {
$(".loader").slideDown();
if (resposta != false) {
// Exibe o erro na div
alert(resposta);
$(".loader").html(resposta);
}
else {
$(".loader").html("Alteração concluída com sucesso!");
}
});
}
var fileup = document.getElementById("fileup").value;
//alert(fileup);
$.post('update.php', { fileup: fileup }, function(resposta) {
$(".loader").slideDown();
if (resposta != false) {
// Exibe o erro na div
alert(resposta);
$(".loader").html(resposta);
}
else {
$(".loader").html("Alteração concluída com sucesso!");
}
});
}
O ficheiro update.php é este:
Código (PHP):
// Recuperamos os valores dos campos através do método POST
$_FILES['fileup']['name'] = $_POST["fileup"];
$uploadpath = '../arquivo/original/'; // directory to store the uploaded files
$allowtype = array('bmp', 'gif', 'jpg', 'jpe', 'png'); // allowed extensions
if($_FILES['fileup']['name']!=""){
$uploadpath = $uploadpath . basename( $_FILES['fileup']['name']); // gets the file name
$sepext = explode('.', strtolower($_FILES['fileup']['name']));
$type = end($sepext); // gets extension
list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']); // gets image width and height
$err = ''; // to store the errors
}
$alwidth = 300; // maximum allowed width, in pixels
$alheight = 300;
if(isset($width) && isset($height) && ($width <= $alwidth || $height <= $alheight)) {
$err .= '<br/>O tamanho mínimo da imagem deve ser: '. $alwidth. ' x '. $alheight; }
if($err == '') {
//echo "erros".$err;
$fileName = $_FILES["fileup"]["name"];
$fileTmpLoc = $_FILES["fileup"]["tmp_name"];
$pathAndName = '../arquivo/original/'.$_POST["artigo"].'.'.$type.'';
$moveResult = move_uploaded_file($fileTmpLoc, $pathAndName);
}
$_FILES['fileup']['name'] = $_POST["fileup"];
$uploadpath = '../arquivo/original/'; // directory to store the uploaded files
$allowtype = array('bmp', 'gif', 'jpg', 'jpe', 'png'); // allowed extensions
if($_FILES['fileup']['name']!=""){
$uploadpath = $uploadpath . basename( $_FILES['fileup']['name']); // gets the file name
$sepext = explode('.', strtolower($_FILES['fileup']['name']));
$type = end($sepext); // gets extension
list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']); // gets image width and height
$err = ''; // to store the errors
}
$alwidth = 300; // maximum allowed width, in pixels
$alheight = 300;
if(isset($width) && isset($height) && ($width <= $alwidth || $height <= $alheight)) {
$err .= '<br/>O tamanho mínimo da imagem deve ser: '. $alwidth. ' x '. $alheight; }
if($err == '') {
//echo "erros".$err;
$fileName = $_FILES["fileup"]["name"];
$fileTmpLoc = $_FILES["fileup"]["tmp_name"];
$pathAndName = '../arquivo/original/'.$_POST["artigo"].'.'.$type.'';
$moveResult = move_uploaded_file($fileTmpLoc, $pathAndName);
}
Está-me a dar o seguinte erro: Warning: getimagesize() [function.getimagesize]: Filename cannot be empty inC:\xampp\htdocs\WebApps\ws_apps\ws_app3\article-details\update.php on line 45
A linha 45 é esta: list($width, $height) = getimagesize($_FILES['fileup']['tmp_name']);
O que tenho que mandar no valor de $_FILES['fileup']['tmp_name'] ?