Hi, you have told me to see the topics but the blocks doesn't works

Hi you have told to me to not post too many questions but the reason is that you told me first to take a look at the topics but the blocks doesn't works, and nobody respond to me with the correct solution, I am a developer but this is code create from other people not to me , it is impossible guess this blocks without any good guide or a correct answer to put geolocation and file upload app, it is a community for give the people informations then we give these informations to all the people thank you for your






attention

I can't read French so I don't know what your blocks do.

But I noticed some of your text blocks have quote marks Inside them, feeding an. activity starter.

That's usually wrong.

1 Like

Simplify. Try to do just one thing at a time.

Make an example project for file upload.

Show your php file and your html upload file.

Geolocation, is this to record the location the user is at, where a photo is taken ?

Explain in words what it is you are trying to do

thank you very much! Now is working but is working the upload only the first time I click and not work the buttom delete post here is the code..`


<?php
// 1) Rilevo Google Translate
$ref = $_SERVER['HTTP_REFERER'] ?? '';
$ua  = $_SERVER['HTTP_USER_AGENT'] ?? '';
if (
     stripos($ref, 'translate.googleusercontent.com') !== false
  || stripos($ref, 'translate.google.com/translate')    !== false
  || stripos($ua,  'GoogleTranslate')                    !== false
) {
    define('SKIP_CORE_AUTH', true);
}
// 3) Il resto di indexb.php...
include 'cookie.php';
// 2) Includo core.php
require_once __DIR__ . '/core.php';
// Gestione AJAX delete/upload media
if($_SERVER['REQUEST_METHOD']==='POST' && isset($_POST['action'])) {
  header('Content-Type: application/json');
  $action      = $_POST['action'];
  $art_id      = (int)($_POST['art_id'] ?? 0);
  $media_type  = $_POST['media_type'] ?? '';
  $media_index = (int)($_POST['media_index'] ?? 0);

  // Controllo proprietario
  $stmt = $conn->prepare("SELECT art_autore FROM articoli WHERE art_id=?");
  $stmt->bind_param("i",$art_id);
  $stmt->execute();
  $owner = $stmt->get_result()->fetch_assoc()['art_autore'] ?? '';
  if($owner!==$_SESSION['username1']) {
    echo json_encode(['success'=>false,'message'=>'Non autorizzato']);
    exit;
  }

  if($action==='delete_media') {
    // Mappa index→campo DB
    $map = ['video'=>'file_name'];
    $imgMap = [1=>'userfile_name',2=>'userfile_name3',3=>'userfile_name4',4=>'userfile_name5'];
    $field = $media_type==='video'
             ? $map['video']
             : ($imgMap[$media_index] ?? '');
    if($field) {
      // Rimuovi file fisico
      $old = $conn->query("SELECT $field FROM articoli WHERE art_id=$art_id")
                  ->fetch_row()[0] ?? '';
      if($old && file_exists("upload/$old")) unlink("upload/$old");
      // Azzeramento DB
      $stmt = $conn->prepare("UPDATE articoli SET $field=NULL WHERE art_id=?");
      $stmt->bind_param("i",$art_id);
      $ok = $stmt->execute();
      echo json_encode(['success'=>$ok]);
    } else {
      echo json_encode(['success'=>false,'message'=>'Campo non valido']);
    }
    exit;
  }
  if($action==='upload_media') {
    // Controllo che sia arrivato un file
    if(!isset($_FILES['file']) || $_FILES['file']['error']!==UPLOAD_ERR_OK) {
      echo json_encode(['success'=>false,'message'=>'Nessun file caricato']);
      exit;
    }
    // Scegli dove salvare
    $ext      = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);
    $newName  = uniqid('media_', true) .'.'. $ext;
    $destPath = __DIR__ . '/upload/' . $newName;
    if(!move_uploaded_file($_FILES['file']['tmp_name'], $destPath)) {
      echo json_encode(['success'=>false,'message'=>'Errore spostamento file']);
      exit;
    }
    // Quale campo aggiornare?
    $mapVideo = ['video'=>'file_name'];
    $mapImg   = [1=>'userfile_name',2=>'userfile_name3',3=>'userfile_name4',4=>'userfile_name5'];
    $field = $media_type==='video'
             ? $mapVideo['video']
             : ($mapImg[$media_index] ?? '');
    if(!$field) {
      echo json_encode(['success'=>false,'message'=>'Campo non valido']);
      exit;
    }
    // Se c’era un vecchio file, cancellalo
    $old = $conn->query("SELECT `$field` FROM articoli WHERE art_id=$art_id")
                ->fetch_row()[0] ?? '';
    if($old && file_exists(__DIR__ . "/upload/$old")) {
      unlink(__DIR__ . "/upload/$old");
    }
    // Aggiorna DB
    $upd = $conn->prepare("UPDATE articoli SET `$field` = ? WHERE art_id = ?");
    $upd->bind_param("si", $newName, $art_id);
    $ok  = $upd->execute();
    echo json_encode(['success'=>(bool)$ok]);
    exit;
  }
// 2) se esiste una funzione csrf_token(), usala; altrimenti usa la sessione
if (function_exists('csrf_token')) {
  $CSRF = csrf_token();
} else {
  if (empty($_SESSION['csrf_token'])) {
    $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
  }
  $CSRF = $_SESSION['csrf_token'];
}
?>

Thank you very much now it's working when i click upload the first time but when I click the second time not working..


and your html ?

use this one is the same of my page

<?php
if ($_SERVER['REQUEST_METHOD']==='POST') {
  header('Content-Type: application/json');
  if (!isset($_FILES['f']) || $_FILES['f']['error']!==UPLOAD_ERR_OK) {
    echo json_encode(['ok'=>false,'msg'=>'no file']); exit;
  }
  @mkdir(__DIR__.'/upload',0775,true);
  $name = 'test_'.time().'_'.basename($_FILES['f']['name']);
  $ok = move_uploaded_file($_FILES['f']['tmp_name'], __DIR__.'/upload/'.$name);
  echo json_encode(['ok'=>$ok,'saved'=>$name,'ini'=>[
    'upload_max_filesize'=>ini_get('upload_max_filesize'),
    'post_max_size'=>ini_get('post_max_size'),
  ]]); exit;
}
?>
<form method="post" enctype="multipart/form-data">
  <input type="file" name="f">
  <button>UP</button>
</form>

``` the problem is the I have do the geolocation function only using visualizzatoreweb but when I used this the upload not work, because at the first the upload was do with webviewextra but if I use webviewextra doesn't work the geolocation..

This could be your issue. The android webview may be struggling to use multipart/form-data, although it should work...

Adjust your html and php to not use this.

A couple of php examples using the web component:

Explain what you are hoping to achieve with geo location

Permissions must be requested successively (one after the other) and only on Android versions where they are available. Storage permissions are no longer available or permitted on all Android versions.

See also here:

In my website with the geolocation I have the exact position with the place
Vitamarinaweb (2).aia (801.4 KB)
this is my project here the geolocation works but the uploading not works.

The location of the device? Is that what you require?

The location of the device

You can get this using geolocation in the html:

This in the webviewer. If you also use webviewextra extension you can upload your files as well :slight_smile:

Also looking at your blocks, the locationChanged blocks are incorrect:

They should be like so:

assumes that your site is receiving this correctly (looks like the user needs to be logged in to the site)

The app told me permess denied because I'm using webviewextra but webviewextra is for file uploading



Use the helper blocks for permissions, and do as @Anke said with respect to asking for many permissions

Because I have read on the web that if you are using webviewextra for file uploading android denied the permissions geolocation, other side if I use geolocalization with webviewer the uploading doesn't work, I ' m working too many days to find the solution but I'm going crazy is too difficult to work in specific blocks created by other people, if there a genius that show me the blocks correct solution, I will thank you him very much, thanks

Where did you read this?

If you are patient, do not create any new topics, and give me a chance, let me see if I can come up with a working solution, that on upload of a file, the file, the filename, and the users location are stored. It may take me a little while to set all of this up.