Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-06-2013, 03:48 PM   PM User | #1
NancyJ
Senior Coder

 
NancyJ's Avatar
 
Join Date: Feb 2005
Location: Bradford, UK
Posts: 3,162
Thanks: 19
Thanked 65 Times in 64 Posts
NancyJ will become famous soon enough
Faking a file upload

I'm trying to write an add-on to some software that will automatically generate images for certain products. I'd like the software to think the file was uploaded like a regular file (when it will in fact have been generated by a script) so that it will do all the things with a new image that it would normally do (naming, location, thumbnails, db entries etc)

The software provides easy hooks into before and after almost every operation so I have no doubt I will be able to 'inject' into the flow ie after POST has been received but before it is processed but can I just put data in to $_FILES and have it work as if the file had been uploaded?
__________________
http://www.hazelryan.co.uk
NancyJ is offline   Reply With Quote
Old 02-06-2013, 04:05 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
There's nothing that would stop you from overwriting $_FILES superglobal, but I wouldn't recommend doing it manually. And whom knows what the software is doing; GET/POST/FILES etc etc are handed to the PHP from the webserver itself, so there is no guarantee by the time it gets to where you manually insert into the $_FILES that it will go back to process.

An alternative would be to curl/socket a new request into the software, and give it the file you want to "upload". That will take it through as a $_FILES itself. That assumes the software will deal with uploads and you don't need to write anything for it.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-06-2013, 05:13 PM   PM User | #3
NancyJ
Senior Coder

 
NancyJ's Avatar
 
Join Date: Feb 2005
Location: Bradford, UK
Posts: 3,162
Thanks: 19
Thanked 65 Times in 64 Posts
NancyJ will become famous soon enough
Turns out the software gives the option to specify that the file is on the server so I was able to create the file and then modify the $_REQUEST to specify that the file was on the server and where and the software does all the rest.
__________________
http://www.hazelryan.co.uk
NancyJ is offline   Reply With Quote
Old 02-06-2013, 05:36 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Quote:
Originally Posted by NancyJ View Post
Turns out the software gives the option to specify that the file is on the server so I was able to create the file and then modify the $_REQUEST to specify that the file was on the server and where and the software does all the rest.
That makes it much easier. Nothing is more frustrating than jumping through hoops with third party software for something that in general is an easy concept. At least they added the functionality right in so you don't need to write something to do it for you.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:52 AM.


Advertisement
Log in to turn off these ads.