0

I am not sure that I am posting on the correct forum. I am working with Linux Centos 7 and I write a bash script which take all files with txt extension from a directory to upload them to the server with php. The bash script seems to find all files inside the directory but it upload only one file and at the end of the process my php page is deleted.

My bash script:

#!/bin/sh
for filename in $(find /home/rico/mywebsite/ -maxdepth 1 -name \*.txt )
do
echo ${filename}
curl -O -X POST -F 'avatar=@'${filename} http://localhost/ions/uploadTXT.php
done;

and my php page is written like that:

<?php
error_reporting(E_ALL); ini_set('display_errors', 1);

$dir = '/opt/lampp/htdocs/ions/upload/';
$filename = basename($_FILES['avatar']['name']); //this var is for the parameter past into input field and used for $handle

if(move_uploaded_file($_FILES['avatar']['tmp_name'], $dir . $filename)) {
}
?>
2
  • Does it echo all filenames correctly? I assume yes because you said that the "script seems to find all files". If you add a line echo $? (= "print return value of previous command") below the curl command to your script, what does it output? Commented May 13, 2020 at 12:41
  • echo ${filename} displayed correctly all files contained in the directory ==> . echo $? output 0. Below the curl command I don't have any errors in output it just shows: ` % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 360M 0 0 100 360M 0 346M 0:00:01 0:00:01 --:--:-- 346M ` Commented May 13, 2020 at 14:01

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.