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)) {
}
?>
echo
all filenames correctly? I assume yes because you said that the "script seems to find all files". If you add a lineecho $?
(= "print return value of previous command") below thecurl
command to your script, what does it output?echo ${filename}
displayed correctly all files contained in the directory ==> .echo $?
output0
. 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 `