0

I have a code that uses numpy.savetxt() and works well in a local server to create .txt files (I use my python code on a php file with shell_exec()), otherwise when I put my website online, the .txt file isn't create (or maybe somewhere but I can't find it).

Is this normal or not? I know it isn't great for the security to directly dowload files on your computer from the web browser but what would be the replacement in order to create and download the created file in the online browser (as on the picture but with a pdf file on chrome)? dowload on chrome

data_to_read is an empty folder

python is the name of the folder with all my python files

web is the name of the folder with all my php files directory picture

Python file test.py takes 4 args in argparse, 2 integers n and t, one probability p and one name s and create a txt file in the data_to_read folder:

a = list(bino_echantillon(args.n, args.p, args.taille))

name = '../data_to_read/'+args.name

if __name__ == '__main__':
    np.savetxt(name, a, delimiter=',')

php:

$PATH= getcwd().'/test.py';
$PATH=str_replace('web', 'python', $PATH);     #(this is a little shortcut to have $PATH= ../python/test.py)
$e=shell_exec("py $PATH -n $n -p $p -t $t -s $s ");

There might be some issues with my code but what I don't understand is that it works locally so I suppose the issue doesn't come from me.

I don't want to mess you up with details of my code but if you need more information please don't hesitate to ask me.

Thanks!

Edit: problem solved by changing py to python!

Wick
  • 93
  • 7
  • If you run `np.savetxt` on your server, then it is saving the text on your server, probably in the directory where the web page lives. You can certainly have your PHP code return the file as a download. Check this question: https://stackoverflow.com/questions/7263923/how-to-force-file-download-with-php – Tim Roberts Aug 26 '21 at 18:02
  • Thank you for your answer! It helps me a lot, however now I can download files online only if there is already the file in the data_to_read folder, I don't know if I'm understandable. For example if there is a test.txt and test2.txt in my data_to_read folder, I can download on chrome test.txt and text2.txt but there are not changed with numpy as I want and I can't create a file named text3.txt. So I believe the issue comes from php shell_exec or numpy savetxt. However it still works on my local server. – Wick Aug 27 '21 at 07:57
  • Your comment seems to have very little to do with the question. Rather than ask a very specific question about one tiny aspect, you should describe your overall goal, and what you've done to get there. We can't offer advice on the overall picture because we don't know it. – Tim Roberts Aug 27 '21 at 17:59

0 Answers0