I need to take a file and move it to a windows machine on a specific folder where it is then to be printed automatically. How would I accomplish something like this? Is it possible with PHP?
Have the user upload the file using a POST form, then use move_uploaded_file to put it into the right folder.
It is possible with PHP. You can upload the file using POST (there are many examples online), and then use - for example - move_uploaded_file to move the file to the appropriate location.
However, you will need to make sure the folder has the appropriate permissions to allow the web server to move files into it.
it is possible with PHP.
but it's also possible with simple copy console command
To have another answer, you need to provide much more information.
Related
Currently, I am putting all files in my public directory which means that anyone can download the file.
However, I don't want anyone else to see that file other than the user who created it. As of right now, I have no control over that. Maybe if I store it in another directory, I will be using middleware to protect it.
But I'm stuck on the part where I can upload the user-uploaded files.
Where is the best directory to put them? I don't have an external server I just have a VPS.
Laravel has a storage folder designed especially for this case. It's not available from outside your server and you will have to serve the files from it through Laravel.
I have a server backup .tar.gz file that I need to automate it's move to another folder, and rename it to a name I can use to later download it via ftp (I can't use wildcard to download the file so I have to know the name in order to grab it). I have the other pieces straighten out, I just need to know how/what my cron job script should look like. Can I do this via PHP? or do I need something else?
Thanks in advance for the help
To answer my own question with some help from #ssaltman above, I did it in PHP and used the following code:
<?php
rename(reset(glob("/exist/path/*.tar.gz")), "/new/path/NEWNAME.tar.gz");
?>
I then attached it to a cron job in cpanel.
I am trying to allow other people to work on my site with me. There are a couple of files/folders that I do not want them to be able to access / see.
One file is dbase.php and the folder is ./crypt/
How do I go about not even allowing them to see that those files are even there?
One of the guys that I'm trying to allow to work on my site says to use PHP's chmod, I looked it up and it does change the file permissions, but what makes it so that he can't put
chmod('dbase.php',0777);
in another file like index.php and change the permissions of the database file and then he can see what I have in there. What I'm trying to hide is the password to my database and a few special variables that run my site. Just some things I'm not comfortable letting roam around with people "I don't 100%" know.
Thanks.
If the guys you are awaring of should be able to edit and upload PHP code to your site, and your site's PHP code should be able to read the secrets file, the is no solution.
They always can upload the code which reads the secret file and outputs its contents.
I have a site that people upload large (2mb-3mb) files to, In large quantities. So I need to store them on an external drive (my drobo). How can I upload files to a folder on the server and then how can I write a php script that retrieves them and lets users download them.
Thanks,
Joey Sacchini
To do this, simply move your files into an accessible space.
http://php.net/manual/en/function.move-uploaded-file.php
Be sure to consider the implications of this though. Once you move an uploaded file to an open directory, anyone can access it. This is very dangerous. Imagine someone uploading a PHP script.
It is best to create a script that fetches files from a location not in the web root. At a basic level, you can store the file's properties, such as original name (you should rename them to something random on disk) and mimetype, to database. Then send the file to the client with readfile().
For downloading backups to your own personal hard drive, just use SFTP.
This is not a quick answer, you need to understand how to upload, retrieve, and save the file to the server; set write permissions for PHP and a few other things. I suggest you try these links to get you started fast:
http://www.w3schools.com/php/php_file_upload.asp
http://www.tizag.com/phpT/fileupload.php
Also visit the PHP reference manual for some great examples.
well u can keep the uploaded files outside of server directory. so if ur server root is /www/htdocs u can keep the files in say /uploaded. so use something like
move_uploaded_file($_FILES['file'],'/uploaded')
this way ur files will be inaccesible to the outside world
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.