I know there are similar questions to this, but I never found a solution to match my case.
so my problem is i have a large file like 130MB with .txt extension.
now I want to upload this file to mysql database.
now I have problem uploading this file it gets timeout, using phpmyadmin.
is there a good way to upload this file using php?
or is there any other way besides those?
Access your server via the console (ssh, telnet, etc) and import the file using the native cli client load data syntax to import your file data:
http://dev.mysql.com/doc/refman/5.1/en/load-data.html
Edit: updating answer based on comments.
Since you can't access mysql via a CLI, i would suggest uploading the text file via ftp, then making a quick php script to import the file via a simple db connect + insert statement..
also use set_time_limit(0) to ensure the script doesn't timeout while executing the query..
You'll also need to make sure you have enough ram available to load the file.
Related
i want to upload sql file into database but it is the size of the file is more. However server's phpmyadmin's import database limit is just 50mb so i am not able to upload it How can i increase this default size limit?
Use SQLYog to import database..your problem will be solved surely.
You can change the limits in the php.ini file. See this post.
As an alternative I recommend using MySQL Workbench rather than SQL Yog. It's freeware.
But with any external tool (Either SQL Yog and MySQL Workbench) you would have to make sure that external access is allowed for your user on your database server instance.
Please note: You have possibly overlooked this, but you mention 'exporting' in your question title, but then 'importing' in the actual question.
Is it possible to upload files (even big files) to a ftp using PHP?
Been reading about ftp_connect() and it looks like I can, or can't I?
I had a look at this example, it's in Italian but you can read the code anyway, if that does what I'm asking, will I have to add an html form? I need to be able to pick up a file form my computer via a web page and upload it to an ftp basically.
Anyone?
Thanks
Especially on large files, you should make sure that the maximum execution time for the script is big enough to complete the transfer before the script is aborted. You can choose the maximum execution time in the php.ini file.
You will have to use an HTML form if you want to pick up the file from your computer via a web page.
As soon as the form is submitted, you can access the file using the $_FILES array. You can use this information to get a temporary path to where the file is stored, and can read it from there to upload it to a remote server using the FTP functions.
You could also split the two processes by using the PHP script only to drop the file into the local file system, and then use a second program which runs locally to do the upload. This has the advantage that you won't run into problems when multiple users upload simultaneously and your FTP is set up in a way that it allows only 1 simultaneous connection. You could program the second script also in PHP and run it using a Cronjob for example once per 30min.
If your goal is a direct stream from your computer to the FTP server, this is not easily possible using a pure PHP / HTML solution since the PHP script is only invoked when the file transfer from your computer to the machine serving the PHP script is complete.
I need to send a file from one PHP page (on which client uploads their files) to another PHP page on another server were files will be finaly stored.
To comunicate now I use JSON-RPC protocol; is it wise to send the file this way?
$string = file_get_contents("uploaded_file_path");
send the string to remote server and then
file_put_contents("file_name", $recieved_string_from_remte);
I understand that this approach takes twice the time than uploading directly to the second server.
Thanks
[edit]
details:
i need to write a service allowing some php (may be joomla) user to use a simple api to upload files and send some other data to my server which analyze them , put in a db and send back a response
[re edit]
i need to create a Simple method allowing the final user to do that, who will use this the interface on server 1 (the uploading) use the php and stop, so remote ssh mount ore strange funny stuff
If I were you, I'd send the file directly to the second server and store its file name and/or some hash of the file name (for easier retrieval) in a database on the first server.
Using this approach, you could query the second server from the first one for the status of the operation. This way, you can leave the file processing to the second machine, and assign user interaction to the first machine.
As i said in my comment, THIS IS NOT RECOMMENDABLE but anyway....
You can use sockets reading byte by byte:
http://php.net/manual/en/book.sockets.php
or you can use ftp:
http://php.net/manual/en/book.ftp.php
Anyway, the problem in your approuch is doing the process async or sync with the user navigation? I really suggest you passed it by sql or ftp and give the user a response based on another event (like a file watching, then email, etc) or using sql (binary, blob, etc)
Use SSHFS on machine 1 to map a file path to machine 2 (using SSH) and save the uploaded file to machine 2. After the file is uploaded, trigger machine 2 to do the processing and report back as normal.
This would allow you to upload to machine 1, but actually stream it to machine 2's HD so it can be processed faster on that machine.
This will be faster than any SQL or manual file copy solution, because the file transfer happens while the user is uploading the file.
If you don't need the files immediately after receiving them (for processing etc), then you can save them all in one folder on Server 1 and set up a cron to scp the contents of the folder to Server 2. All this assuming you are using linux servers, this is one of the most secure and efficient ways to do it.
For more info please take a look at http://en.wikipedia.org/wiki/Secure_copy or google scp.
I am trying to create a SQLite database file for iOS and Android. However, I am running into an issue I have, so far, not been able to solve.
Point is, I know how to create a SQLite database on both devices, and I know how to do it in PHP, but somehow they cannot read each-others databases.
How I create/open the sqlite file in php:
$dbhandle = sqlite_open('icddb.sqlite', 0777, $error);
I do queries like this:
sqlite_exec($dbhandle,$query);
When I put the filled database to iOS, this message is displayed:
file is encrypted or is not a database
How can this be solved? I have same problem when I create the SQLite file with firefox plugin 'SQLite Manager'
Note: PHP is in any case able to open the SQLite file.
Edit:
Apparently the latest stable PHP version creates a SQLite v2 file instead of a v3, which is used by all other. This probably is also my fix.
This is a SQLite version mismatch problem, Related Link:
Error: file is encrypted or is not a database
Probably they use different SQLite implementations or something similar.
Run a script that outputs the contents you want to send (for example, output the data in JSON)
Then parse the contents on the other side.
I have created a PHP script to upload a file, unfortunately I don't have permission to save files on the disk. I have to upload an excel file (using phpexcel), then I have to read all the rows in the file and save to disk, Is there any way for me to process this file without saving to disk, I tried to read $_FILES['file1']['tmp_name'] but it doesn't work.
could u please suggest a method to process this file
Thank you for the consideration
By "save to disk" you mean to send it back to the user for him to download it?
Usually, you shall have write access to (at least) the PHP temporary directory. Have you tried whether the form and script work in a local environment? Maybe there is something elso wrong with the upload?!
Finally: Why so you not have the persmission to save files? Are you allowed to create a subdirectory below you PHP file (via FTP) and give that one full permissions?
I tried to read $_FILES['file1']['tmp_name']
most probably you have just encountered an error.
that happens to beginner programmers very often
you have to repair that error instead of looking for odd workarounds.
Start from checking $_FILES['file1']['error']
what does
var_dump($_FILES['file1']['error']);
say?
Instead of sending your files with a form (multidata over HTTP POST), you can send your files with a little bit of Javascript with the HTTP PUT method to your server.
This scenario is described in the official documentation of PHP -> PUT method support.
Due some restrictions described in the documentation you have to do some workarounds to be able to work it properly.
You can read the direct input stream from your Webserver. The data will be piped from your Webserver to your PHP programm and will be only saved in memory.
To do a PUT Ajax call with jQuery was answered here. You can use a jQuery upload plugin like Uploadify.