Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Bom dia a todos!
Estou começando a aprender php (programo em asp e gostaria de migrar) e gostaria que me explicassem o que está ocorrendo, onde estou errando.
Tenho sistema de upload, utilizando o plugin Uploadify, que estava funcionando certinho até eu incluir um script para redimensionamento automático.
Assim funcionava:
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = 'fotos/' . $_FILES['Filedata']['name'];
move_uploaded_file($tempFile,$targetFile);
echo "1";
}
Assim não funciona (na vdd o Upload parece ser efetuado com sucesso, mas os arquivos não sobem pra pasta)
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
$targetPath = str_replace('//','/',$targetPath);
$targetFile = 'fotos/' . $_FILES['Filedata']['name'];
move_uploaded_file($tempFile,$targetFile);
}
$imgsize = getimagesize($targetFile);
switch(strtolower(substr($targetFile, -3))){
case "jpg":
$image = imagecreatefromjpeg($targetFile);
break;
case "png":
$image = imagecreatefrompng($targetFile);
break;
case "gif":
$image = imagecreatefromgif($targetFile);
break;
default:
exit;
break;
}
$width = 700; //New width of image
$height = $imgsize[1]/$imgsize[0]*$width; //This maintains proportions
$src_w = $imgsize[0];
$src_h = $imgsize[1];
$picture = imagecreatetruecolor($width, $height);
imagealphablending($picture, false);
imagesavealpha($picture, true);
$bool = imagecopyresampled($picture, $image, 0, 0, 0, 0, $width, $height, $src_w, $src_h);
if($bool){
switch(strtolower(substr($targetFile, -3))){
case "jpg":
header("Content-Type: image/jpeg");
$bool2 = imagejpeg($picture,$targetPath.'fotos/'.$_FILES['Filedata']['name'],80);
break;
case "png":
header("Content-Type: image/png");
imagepng($picture,$targetPath.'fotos/'. $_FILES['Filedata']['name'];
break;
case "gif":
header("Content-Type: image/gif");
imagegif($picture,$targetPath.'fotos/'.$_FILES['Filedata']['name']);
break;
}
}
imagedestroy($picture);
imagedestroy($image);
echo '1'; // Important so upload will work on OSX
Eu já alterei a $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/'; pelo caminho completo até minha pasta, assim como a $targetPath = str_replace('//','/',$targetPath); e efetuei alguns testes, mas não funciona.
As permissões estão corretas.
Desculpem-me se a questão for muito trivial.
Carregando comentários...