Messages - The Code Queryer [ switch to compact view ]

Pages: prev1 2 3 [4] 5 6 7next
16
Developer's Corner / File Upload With Php
« on: April 08, 2019, 03:21 PM »
Php Programmers,

I am trying to build a file upload script with php but struggling. Need your urgent assistance.
Here are the requirements:


START OF REQUIREMENTS

* If directories "uploads/videos/id_verifications/$user" do not exist then they must be created. Else, not.
NOTE: Only the script must be able to create these directories and write to them (add files, delete files, copy files there, copy files from there, etc.) and no external domain must have these privileges. No other scripts must be executable from these directories.

* If File already exists then should echo error. Else, not.
Should check with php function: file-exists().
https://www.php.net/manual/en/function.file-exists.php

* Uploaded File should only be video files (.wav, .mp4, etc.). Should echo error if File Types are otherwise.

* Script should check whether the file upload was successful or not.
Should check with php function: is_uploaded_file().
http://php.net/manual/en/function.is-uploaded-file.php

To detect File Details, should use php functions:
* file_info() & mime_content_type():
https://www.php.net/manual/en/function.finfo-file.php
https://www.php.net/manual/en/function.mime-content-type.php

* Uploaded File should not be more than 100MB. Should echo error if File Sizes are otherwise.
Should check with php function: file_size():
https://www.php.net/manual/en/function.filesize.php

* Temporary File should be created at first and then moved to the following permanent directory: uploads/videos/id_verifications/$user.
Moving of directory should be done using php function: move_uploaded_file
https://www.php.net/manual/en/function.move-uploaded-file.php

* Uploading File Name should be renamed to: $user_id_verification
File Renaming should be done using php function: rename():
https://www.php.net/manual/en/function.rename.php
So, if file name is "my_id.mp4" and User's username is "tommy_boy" then File Name should be renamed to: "tommy_boy_id_verification.mp4".
If file name is "my_id.wav" and User's username is "tony_boy" then File Name should be renamed to: "tony_boy_id_verification.wav".
(NOTE: On the above 2 example lines, the File extensions are different).

* User must get notified that, file has been uploaded successfully. If uploading fails then user must get echoed error.

* All Errors should be echoed using traditional: $Errors[] = "Error message goes here";

* Php code must be in procedural style as I do not know OOP.

* You must include understandable comments on your codes so I can understand them and have no questions.

END OF REQUIREMENTS


Q1. Are there anything else, in terms of security, that I should have as "Requirements" ?


17
Developer's Corner / Re: Sql Syntax Error
« on: April 08, 2019, 01:52 PM »
Here is the link to the SQL syntax for the SELECT command in MariaDB. That is the database software your error code says you are using.

SELECT
    [ALL | DISTINCT | DISTINCTROW]
    [HIGH_PRIORITY]
    [STRAIGHT_JOIN]
    [SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_BUFFER_RESULT]
    [SQL_CACHE | SQL_NO_CACHE] [SQL_CALC_FOUND_ROWS]
    select_expr [, select_expr ...]
    [ FROM table_references
      [WHERE where_condition]
      [GROUP BY {col_name | expr | position} [ASC | DESC], ... [WITH ROLLUP]]
      [HAVING where_condition]
      [ORDER BY {col_name | expr | position} [ASC | DESC], ...]
      [LIMIT {[offset,] row_count | row_count OFFSET offset}]
      [PROCEDURE procedure_name(argument_list)]
      [INTO OUTFILE 'file_name' [CHARACTER SET charset_name] [export_options]


INTO DUMPFILE 'file_name' INTO var_name [, var_name] ]

      [[FOR UPDATE | LOCK IN SHARE MODE] [WAIT n | NOWAIT] ] ]


export_options:
    [{FIELDS | COLUMNS}
        [TERMINATED BY 'string']
        [[OPTIONALLY] ENCLOSED BY 'char']
        [ESCAPED BY 'char']
    ]
    [LINES
        [STARTING BY 'string']
        [TERMINATED BY 'string']
    ]

By your own admission, you stated that you are not a programmer and that you starting to learn. No problem, in that case you should first check if your query works in a database client before you try to put it into PHP scripting. A database client usually has much more helpful ways to describe what is going wrong with your SQL query. on the MariaDB site, the use of HeidiSQL is recommended.

Your query:
SELECT * FROM browsing_histories WHERE username = ?

Doesn't seem it is properly terminated.
And is the question mark allowed as parameter content?
Or is the query treated as if you are looking for one or more user names that have the name '?' ?

Anyway, a database client could already have told you that. More extensive database clients often come with an option to see how long a query takes on the database you are connected to, which tables/indexes are consulted for that query, etc. Might not be useful information for you right now, but if your thing picks up and needs to scale, you will be very glad you have access to such tools.

Another tip: looking for optimizations to make your code faster? If there is any access to any type of database involved, check first how you can optimize your queries first. That is more often than not where you can gain a lot more. Fast code or slow code, both wait just as long for your database query to produce results...

[attachthumb=#,msg428965][/attachthumb]

Without access to your database, I just started up my XAMPP environment (which is useful for PHP script development on Windows) to connect to a MySQL database (PHPmyadmin) and show you how the query should be.

I cannot state enough the importance of using a database client first for checking database queries that need to be in code. Which in and of itself is already a sub-optimal practice (for applications that need to scale), but PHP, so who cares.

Ok. I did as you suggested. tested my query in PhpMyAdmin in my xampp. Get error:
"Error
Static analysis:

1 errors were found during analysis.

Unexpected character. (near "?" at position 50)
SQL query: Documentation

SELECT * FROM browsing_histories WHERE username = ? LIMIT 0, 25

MySQL said: Documentation

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '? LIMIT 0, 25' at line 1"

Anyway, you use "?" as placeholders when coding prepared statements and that is why the "?" came-along.

Q1. Anyway, how-about showing me how the query should have been in php ?
Q2. How-about showing us a sample pagination code where username searches can be done ?

So I can learn from your sample and others can learn too ? :)
I been searching on google etc. for weeks now and can't find a tutorial that teaches how to build a pagination script with search feature (eg. username searches) using procedural style and mysqli. I do not know pdo or oop style yet.
And so, your code sample would most likely be the only sample available online. Definitely, will get google indexing your post!

18
Developer's Corner / Re: if(file_exists..) is Failing!
« on: April 08, 2019, 01:45 PM »
In your code, the commented out version of the line is closer to what you want.  By putting double quotes around everything you are not getting the string you want.

Here's a tip for you, use some intermediate variables.  Instead of going right to
Code: PHP [Select]
  1. if(file_exists($directory_path . $user . '/' . $file_name))

Try instead using a few lines like
Code: PHP [Select]
  1. $fpath = $directory_path . $user . '/' . $file_name;
  2. echo 'About to check if this file exists: ' . $fpath;
  3. if (file_exists($fpath))

Then maybe you will see the problem with how you are creating the full file path.  You might find that you've got an extra / where you dont expect it, or that $user is not what you expect, etc.

Thanks. All this time was experimentin on my localhost xampp. Now tried my website and get this error:
"Warning: mkdir(): Permission denied in /home/domain/public_html/upload.php on line 35".

19
Php & cURL Folks,

I am a php student. I struggle with php and cURL the most.
Is anybody here interested in program trades ? This is where I will give you .exe bots and you will give me .php bots.
When I say "bots", I mean automation tools and not illegal bots such as spam bots and the like.

Why am I looking forward to this trade ? It's like this. I learnt how to build .exe bots and now I want to build web versions of them. Problem is, I am struggling with php and cURL. I am not a real programmer who uses programming languages to build automation tools. I use GUI programming tools. I just click buttons and the automation tools are built as the tool spits the code to C# and compiles them.
Since I am not a real programmer then you can understand why I am struggling with php. Checkout my threads to see where I am stuck on php.
And, checkout my "IDEA" threads for some of my internet business ideas.
I need some php developer to build me this:
https://www.donationcoder.com/forum/index.php?topic=47463.msg428961#msg428961
I will supply you with a .exe copy. You can give it away or sell it aswell as use it. I don't care. You should give me same privilege. I just want to grab a php version and learn from the source code how to automate the web using php and cURL. That's all. I've been honest with you guys here, right from the beginning. So, how-about a trade ?

20
Post New Requests Here / IDEA: Searchengine Scraper
« on: April 06, 2019, 02:00 PM »
Hi,

My idea is a searchengine scraper.
It is like this ....
You come to a webpage and you see a search box (like google and the like). You type a url and click the "Scrape SERPs" button.
Now, the web app would visit the SERP page and scrape all the result links. It would follow to the next SERP pages and do likewise until it has met the dept you put.
A spider that visits SERP pages and scrapes all the result links. It then saves them on the website's database under your member username. Others can search band see what you scraped by doing your Username search. Likewise you can do too.
The scraper would scrape not only the links but their anchor texts, page titles, page meta keywords and meta descriptions.
In other words, a searchengine scraper. A web app. Built with php.
Anybody can build this then do the community a favour by releasing the source code here and on the gpl so we can learn from your source code. I am php student. I reckon cURL is good for the job.

Anyone like this idea,. Give it a thumbs up! :up:

Just imagine, you can scrape any searchengine with this.
I have built a .exe one. Anyone who builds a .php one then I am willing to trade or willinbg to give you a copy if you give me the .php copy along with comments so I can learn from your code.

Pages: prev1 2 3 [4] 5 6 7next
Go to full version