ASP File Upload Hack
November 24, 2006
In the morning I continued work on the CLR CMS by fine tuning the update of text files through ASP. Using the RegExp Object I am able to provide only <br> replacements to vbcrlf from a <textarea> and vice versa. The text file is used in a Flash website which has text fields set to render as HTML.
Later in the afternoon I started AK’s book cover which needed some minor tweaks. Later it turned out we had to revert to the original artwork I had created which unfortunately I had not saved anymore after further edits. In the last few days I have learnt 2 very old lessons all over again.
- Never delete any project files untill the project is completed and backed up
- Always create new versions of the work file when doing major changes
Later in the evening I got home early as tomorrow we are going out to Ro for the weekend. My eyes are really over worked and they need some serious rest. In the last 15 to 20 days the CLR project and the Doyl’y project were completed. Only the fag end of the CMS for CLR is left. It detained majorly because of the image upload section. ASP doesnt have a file upload object like PHP does. So I simply sent the form data from an ASP page to a PHP page to upload the file and returned the user back to the ASP page. There were some problems, notably the width and height of the image uploaded had to be specific. It took some time and by midnight, I had a decent solution. I was not a PHP programmer at all. But it was pretty straighforward. You can get a very simple file upload script here. After this little workaround I completely switched to PHP from ASP!
- The form in the ASP page sends data to a PHP page through a basic HTML form with action set to “name_of_the_page.php”. This can be done by offering to upload image which takes the user to the PHP page, uploads it from there and returns back to the ASP page.
- The data that goes to PHP contains the file to be uploaded along with its required width, height and destination in hidden fields.
- The PHP page uploads the image to a temporary location with a fixed name (“tmp_images/tmp_jpg”).
- Then it checks the size of this uploaded image (not the temp image that even PHP created)
- It validates this information with the width and height details that came in with the from as hidden fields.
- If it is ok then the script copies the image from the tmp location and pastes it into the permanent location(“images/the_image.jpg”).
- Then PHP redirects back to the ASP page where the new image is loaded from its location.
Crazy solution but I felt good that it worked. It’s 2 AM in the night and I have an alarm for 6:30 AM! The car will come at 7 and we leave immediately. I hope it turns out a relaxing weekend. I have been on a detox diet for the last 7 days which I will break from and continue from Monday!