Post file from Command Prompt - php

I am working on a batch-script that makes a SQL query and saves it to a file. The file will then be handled by PHP. Is it possible to POST a file from Windows CMD to a PHP site so it can be handled by php with $_FILES['someFile']?

Yes, you can use curl for this.
curl -F someFile=#localfile.sql http://example.org/upload

Or you can use wget.
wget --post-file=file.jpg http://yourdomain.com/target.php

Related

Download a zip file using curl or wget

I need to download several zip files from this web page ....
http://www.geoportale.regione.lombardia.it/download-pacchetti?p_p_id=dwnpackageportlet_WAR_geoportaledownloadportlet&p_p_lifecycle=0&metadataid=%7B16C07895-B75B-466A-B980-940ECA207F64%7D
using curl or wget, so not in interactive way,
A sample url is the follow ...
http://www.geoportale.regione.lombardia.it/rlregis_download/service/package?dbId=323&cod=12
If I use this link in a new browser tab or window, all works fine but using curl or wget it's not possible to download the zipfile.
Trying to see what happen in the browser using Firebug, or in general the browser console, I can see that there is first a POST request and then a GET request (using Firebug ... ), so I'm not able to reproduce these requests using curl or wget.
Could be also that some cookies are sets in the browser session and the links do not work without that cookie?
Any suggestion will be appreciated ....
Cesare
NOTE: when I try to use a wget this is my result
NOTE 2: 404 Not found
NOTE 3 (the solution): the right command is
wget "http://www.geoportale.regione.lombardia.it/rlregis_download/service/package?dbId=323&cod=12"
then I've to rename the file in something like "pippo.zip" and this is my result, or, better using the -O option in this manner
wget "http://www.geoportale.regione.lombardia.it/rlregis_download/service/package?dbId=323&cod=12" -O pippo.zip
Looking at your command, you're missing the double quotes. Your command should be:
wget "http://www.geoportale.regione.lombardia.it/rlregis_download‌​/service/package?dbI‌​d=323&cod=12"
That should download it properly.

How to use cron job on localhost in Windows with Laravel 5

I found this post here : Run Cron Job on PHP Script, on localhost in Windows which is working perfectly. Instead of a PHP file I want to run an URL instead, like http://localhost/test-cron-job
I tried to simply change this line here:
"C:\xampp\php\php.exe" -f "C:\Users\Matthew\Documents\Work\cronjob\my_script.php"
to this:
"C:\xampp\php\php.exe" -f "http://localhost/test-cron-job"
But it is not working at all. What can I do to make this work?
It doesn't work because php.exe is supposed to execute a PHP file. When you point it to a URL it doesn't know what to do.
What you need is something like curl for Windows and then you can make a HTTP request:
curl http://localhost/test-cron-job

Run javascript function from cmd

Hi i was trying to emulate a post created from javascript in a site with curl from a php script but it seems some variables have the same name and they get overwritten, is there a way to run the script itself from command promt, assuming i make the necessary changes to it?
Well ... you can always install NodeJS and then just write in terminal: node <filename>

Cronjob using CURL/WGET

I want to run a PHP script every 15 minutes using either CURL or WGET.
This PHP file is in a local folder:
/home/x/cron.php
How would I run this using CURL/WGET?
It doesn't work when I try to run
curl /home/x/cron.php
Thank you!
CURL and WGET are more adecuate for URLs like http://myhost.com/cron.php
When the script is offline, you would better run it using php CLI:
Ex:
php -q cron.php
Just do something like this:
/usr/bin/php /home/x/cron.php
cURL/wget is for HTTP actions. If your PHP script is on the same system, you don't want to load it over HTTP. (You can, of course, if it is accessible over HTTP, but I don't think that is what you want.) Just call it directly.
Alternatively, you can set the execute permission on your script and throw in a shebang line for PHP:
#!/usr/bin/php
Then, just put your PHP script in crontab directly.
If you're using CURL or WGET, I believe you'll need to pass in the path as a URL. If you want to run the php script on the command line, you'll need to use the the php CLI

run php script after wget download is complete

I need to get notification on some script that file has been successfully downloaded with WGET, so I'll need to upload it to another server. Can it be done?
Thanks!
wget "http://example.com/path_to_file.tar.gz" && php scriptname.php file.tar.gz
Why not perform the download with cUrl in php instead, then the PHP script can be run in the background and continue when the download is complete?

Categories