View Full Version : Image/file upload doing my nut

04-07-2003, 06:43 PM
Does anyone have a script that will accept an image upload and saves the file to a directory. I'm looking for something in its simplest form, nothing fancy, so I can learn. So far I've found the php manual of questionable use and tutorials that plain don't work (one on phpbuilder.com).

Any help greatly recieved. :)

04-07-2003, 07:23 PM
most of the ones you'll find online will be outdated due to not using the $_FILES array for variable access calls.

$upload_error = '';
if(isset($_FILES['imgref']['tmp_name']) && $_FILES['imgref']['tmp_name'] !== "none")
$f_type = @getimagesize($_FILES['imgref']['tmp_name']);
if($f_type[2] > 0)
// ftype[2] returns the filetype - where a valid image is always above zero
// you could type test further - maybe !== 2 ~ not jpeg or somesuch.
if($_FILES['imgref']['size'] < 116000)
// check image size in bytes
echo 'Your submission has been saved and our administrator will check it shortly, thankyou.<br /><br />';
$upload_error .= 'The file you uploaded was not below 116kb.<br />';
$upload_error .= 'The file you uploaded was not a valid image file.<br />';

$upload_error .= ($upload_error == '') ? '' : '<br /><br />';

where the input type="file" is named imgref

should point you in the right direction anyway

04-07-2003, 07:36 PM
ug , beaten to it :D - but I started so I will finish ~

function imup($path , $name=''){
$name = $_FILES['infile']['name'];
copy($_FILES['infile']['tmp_name'], $path . $name);
//get some info//
print_r( getimagesize($path . $name) );

//if we have an uploaded file//
if (is_uploaded_file($_FILES['infile']['tmp_name'])) {
//absolute filesystem path is safest , though ../images etc should work//
//you could add your own image name assuming you know the filetype//
imup('h:/phpdev/www/' , NULL);

<form enctype="multipart/form-data" name="bella" action="<?=$_SERVER['PHP_SELF'];?>" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="1000">
Send this file: <input name="infile" type="file">
<input type="submit" value="Send File">

04-10-2003, 10:40 PM
My PHP is version 4.0.6, predating $_FILES :confused::(

I understand $HTTP_POST_FILES is depriciated and that $_FILES is 'autoglobal'. Otherwise what is the difference between these two? There's little info on $HTTP_POST_FILES in the manual, all attention seems to be on $_FILES...

04-11-2003, 05:41 AM
problem is that there were security issues with the way that PHP dealt with file-uploads , hence the change ... really is time to upgrade dude :D

04-11-2003, 10:02 AM
even on older builds you should be able to use $HTTP_POST_FILES in place of all the $_FILES calls - just run a search..replace in your fav editor.

04-11-2003, 10:25 AM
k, I'll have another bash, :) I'll email my host too and ask 'em if they've any plans to upgrade.

04-11-2003, 10:39 AM
No kidding that version is like 2 years old. As firepages said there have been major security fixes and enhancements done since then. If your host doesn't want to upgrade i'd find a new host.

04-11-2003, 11:25 AM
A response within half an hour, not bad, well this is what they say...

We realise the security implications and that the version is some way
behind, however, we are unable to upgrade the software before SUN
Microsystems release the update without voiding the warranty on the
server as such we will not do this. As soon as SUN release the package
upgrade for the RaQ 550's it will be installed, unfortunately we do not
know when this will be.