C
C
chifafox2019-04-05 01:53:11
PHP
chifafox, 2019-04-05 01:53:11

When sending a picture to the server, a 404 error is issued. What to do?

I generate a picture and send it to the server, but in the end I get 404. I can’t understand what’s wrong.

// Postcard generation

var canvas = document.getElementById('otkrytka');
ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, 980, 480);

pic = new Image(980, 480);
pic.src = $('.block2__card').css('backgroundImage').replace('url(','').replace(')','').replace(/\"/gi, "");
pic.onload = function(){
ctx.drawImage(pic, 0, 0);

ctx.font = '25px Karton';
ctx.fillStyle = '#00bcbd';
ctx.textAlign = 'center';
ctx.fillText( $('.block2__name').text(), 608, 149);

ctx.fillStyle = '#000000';

console.log( $('.block2__text .first-line #whattodo').text().length );

if( $('.block2__text .first-line #whattodo').text().length <= 28 ) {
var a = 0;
ctx.fillText( $('.block2__text .first-line').text().replace(/(<([^>]+)>)/ig,""), 608, 202);
}
else {
var a = 1;
ctx.fillText( 'Приглашаю тебя', 608, 202);
ctx.fillText( $('.block2__text .first-line #whattodo').text().replace(/(<([^>]+)>)/ig,""), 608, 230);
}

ctx.fillText( $('.block2__text .second-line').text().replace(/(<([^>]+)>)/ig,""), 608, (230 + (a*28)));

ctx.fillStyle = '#00bcbd';
ctx.textAlign = 'left';
ctx.fillText('«Не торты, а торты»', 375, (258 + (a*28)));

ctx.fillStyle = '#000000';
ctx.textAlign = 'left';
ctx.fillText('по адресу Куйбышева, 57.', 567, (258 + (a*28)));

ctx.textAlign = 'center';
ctx.fillText( $('.block2__sender').text(), 608, (311 + (a*28)));

var dataURL = canvas.toDataURL('image/png');

var filename = ( Math.random() * (100000 - 1) + 1 );

$.ajax({
type: 'POST',
url: '/ajax/save.php',
data: {
imgBase64: dataURL,
name: filename
}
}).done(function(o) {
$('.block2__social-item.vk').attr('href', 'https://vk.com/share.php?url=http:/http://netorty-...' + filename);
$('.block2__social-item.ok').attr('href', 'https://connect.ok.ru/offer?url=http://http://neto...' + filename);
$('.block2__social-item.gplus').attr('href', 'https://plus.google.com/share?url=http://http://ne...' + filename);
$('.block2__social-item.twi').attr('href', 'http://twitter.com/share?text=Нетортыаторты&url=ht...' + filename + '&hashtags=люблюторты');
$('.block2__social-item.fb').attr('href', 'www.facebook.com/sharer/sharer.php?u=http://http:/...' + filename);

$('.block2__save').attr('href', 'https://netorty-privet.ru//otkrytki/' + filename + '.png');

$('.block2__social-list, .block2__controls, .block2__controls-text').removeClass('hidden');
});
}
});

<?php
$img = $_POST['dataURL'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = $upload_dir . mktime() . ".png";
$success = file_put_contents($file, $data);
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman, 2019-04-05
@procode

here the cap next to me tells me that if 404 means, he says, he wrote the url incorrectly))
I probably agree with him

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question