Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts

    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?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    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.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •