Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Python Feedback on a program I made.

skifli

Backend Developer
Hi CF,

I would like to ask for feedback on a project of mine I made in Python & PHP. It is a program that allows you to wirelessly share files with other devices on your network. Any device that can access the webpage for the server can upload and downloads files.

Github: https://github.com/didlly/File-Sharer

NOTE: Currently the program only supports Windows.
 
Last edited:
Ok, so I'm not sure if this is supposed to happen, but when I open the main.exe a terminal opens. This is what it shows:
Code:
[15-12-2021-07:49:31] - Definied window instance within variable 'window'.

[15-12-2021-07:49:31] - Defined variable 'window_width' and set it's value to 150.

[15-12-2021-07:49:31] - Defined variable 'window_height' and set it's value to 150.

[15-12-2021-07:49:31] - Defined variables 'screen_width' and 'screen_height' and set their values to 1920 and 1080 respectively.

[15-12-2021-07:49:31] - Defined variables 'x_cordinate' and 'y_cordinate' and set their values to 885 and 465 respectively.

[15-12-2021-07:49:31] - Defined window size and set its value to '150x150+885+465'.

[15-12-2021-07:49:31] - Made the window non-resizeable.

[15-12-2021-07:49:31] - Set the window's title to 'File Sharer'.

[15-12-2021-07:49:31] - Made a button to start the server and assigned it the name 'start_button'.

[15-12-2021-07:49:31] - Specified coords for 'start_button' to be placed.

[15-12-2021-07:49:57] - Worked out the command to be written to the bat file (cd C:\Users\*****\Downloads\File-Sharer-main\src\php && php -S 192.168.18.164:80 -t C:\Users\*****\Downloads\File-Sharer-main\src\server -c C:\Users\*****\Downloads\File-Sharer-main\src\server\php.ini) and saved it to the variable cmd.

[15-12-2021-07:49:57] - Opened C:\Users\*****\Downloads\File-Sharer-main\src/run.bat in write mode.

[15-12-2021-07:49:57] - Wrote cd C:\Users\*****\Downloads\File-Sharer-main\src\php && php -S 192.168.18.164:80 -t C:\Users\*****\Downloads\File-Sharer-main\src\server -c C:\Users\*****\Downloads\File-Sharer-main\src\server\php.ini to the bat file.

[15-12-2021-07:50:01] - Opened the server and assigned it the name 'bat'.

[15-12-2021-07:50:01] - Globalised PID of server (11244)

[15-12-2021-07:50:19] - Opened the server page in the default web browser.

[15-12-2021-07:50:19] - Made a button to stop the server and assigned it the name 'end_button'.

[15-12-2021-07:50:19] - Specified coords for 'end_button' to be placed.

After the terminal opened a mini window opened with a button saying start server. When I click it, a web page opens in a browser (192.168.18.164) and it's just blank. I can't remember if it was before or after the web page opened, but another terminal opened showing this:
Code:
C:\Users\*****\Downloads\File-Sharer-main\src>cd C:\Users\*****\Downloads\File-Sharer-main\src\php   && php -S 192.168.18.164:80 -t C:\Users\*****\Downloads\File-Sharer-main\src\server -c C:\Users\*****\Downloads\File-Sharer-main\src\server\php.ini
[Wed Dec 15 07:51:41 2021] PHP 8.1.0 Development Server (http://192.168.18.164:80) started
[Wed Dec 15 07:51:48 2021] 192.168.18.164:54903 Accepted
[Wed Dec 15 07:52:06 2021] 192.168.18.164:54903 [200]: GET / - Uncaught TypeError: array_diff(): Argument #1 ($array) must be of type array, bool given in C:\Users\*****\Downloads\File-Sharer-main\src\server\index.php:128
Stack trace:
#0 C:\Users\*****\Downloads\File-Sharer-main\src\server\index.php(128): array_diff(false, Array)
#1 {main}
  thrown in C:\Users\*****\Downloads\File-Sharer-main\src\server\index.php on line 128
[Wed Dec 15 07:52:06 2021] 192.168.18.164:54903 Closing
[Wed Dec 15 07:52:32 2021] 192.168.18.164:65190 Accepted
[Wed Dec 15 07:52:32 2021] 192.168.18.164:65190 [404]: GET /favicon.ico - No such file or directory
[Wed Dec 15 07:52:32 2021] 192.168.18.164:65190 Closing
[Wed Dec 15 07:52:46 2021] 192.168.18.164:53890 Accepted
[Wed Dec 15 07:52:46 2021] 192.168.18.164:53890 [200]: GET / - Uncaught TypeError: array_diff(): Argument #1 ($array) must be of type array, bool given in C:\Users\*****\Downloads\File-Sharer-main\src\server\index.php:128
Stack trace:
#0 C:\Users\*****\Downloads\File-Sharer-main\src\server\index.php(128): array_diff(false, Array)
#1 {main}
  thrown in C:\Users\*****\Downloads\File-Sharer-main\src\server\index.php on line 128
[Wed Dec 15 07:52:46 2021] 192.168.18.164:53890 Closing
[Wed Dec 15 07:53:23 2021] 192.168.18.164:55481 Accepted
[Wed Dec 15 07:53:23 2021] 192.168.18.164:55481 [200]: GET / - Uncaught TypeError: array_diff(): Argument #1 ($array) must be of type array, bool given in C:\Users\*****\Downloads\File-Sharer-main\src\server\index.php:128
Stack trace:
#0 C:\Users\*****\Downloads\File-Sharer-main\src\server\index.php(128): array_diff(false, Array)
#1 {main}
  thrown in C:\Users\*****\Downloads\File-Sharer-main\src\server\index.php on line 128
[Wed Dec 15 07:53:23 2021] 192.168.18.164:55481 Closing

Btw the ***** it my username, but I've replaced it with this
 
I've updated the code with a fix. When I update the code, I make sure the /uploads folder is empty of all files from testing the server. However, since it is empty Github doesn't bother adding the folder to the repository. At line 128, where the error occurred, PHP tries to search for all files in the folder. However, since there is no folder it doesn't return an array as expected, which results in an error.
 
Perhaps in GitHub add a simple .txt file under /uploads like a readme or something so then it will still create that folder for you. Maybe that will work?
 
Yeah, as I said in a previous message I've updated the code with a fix. There is a new file called PLACEHODER in 'src/uploads/' that gets deleted when you run the script. Redownload the files and it should now work.
 
Last edited:
Yeah, as I said in a previous message I've updated the code with a fix. There is a new file called PLACEHODER in 'src/uploads/' that gets deleted when you run the script. Redownload the files and it should now work.
In the future you can also do things like this:
Code:
import os
path = "folder/path/here"
folderexists = os.path.isdir(path)
if not folderexists:
    os.mkdir(path)
This checks if the folder exists, and if not will create the folder automatically.

You could also add a file:
Code:
f = open(path + "/filename.txt", "a")
f.write("This is my readme file.")
f.close()
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom