Page 2 of 2
Re: $_FILES problem with uploading
Posted: Sun Feb 17, 2008 9:45 pm
by danielfs1
Actually we are not trying to save space as much as just being able to resize the picture before we put it into the database.
Anyways im not at work, but will the mysql_real_escape_string work with pear? I think thats why we were using addslashes.
Re: $_FILES problem with uploading
Posted: Mon Feb 18, 2008 1:03 am
by jmut
danielfs1 wrote:Actually we are not trying to save space as much as just being able to resize the picture before we put it into the database.
Anyways im not at work, but will the mysql_real_escape_string work with pear? I think thats why we were using addslashes.
nothing todo with pear. php.net/mysql_real_escape_string.
And addslashes is one function I see no use of. stripslashes() I use once (to handle magic_quotes)
Re: $_FILES problem with uploading
Posted: Mon Feb 18, 2008 9:45 am
by danielfs1
Well the addslashes wasn't what is corrupting it.
Its this line
imagejpeg($NEW_IMAGE, $file, 85);
After commenting it out, the picture will show up but won't be resized.
Also I'm getting an error with this:
imagecopyresampled($NEW_IMAGE, $OLD_IMAGE, 0, 0, 0, 0, $NEW_WIDTH, $NEW_HEIGHT, $ORIGINAL_WIDTH, $ORIGINAL_HEIGHT);
imagecopyresampled(): supplied argument is not a valid Image resource in
Here is the code for the particular section:
Code: Select all
$NEW_IMAGE = imagecreatetruecolor($NEW_WIDTH, $NEW_HEIGHT);
$OLD_IMAGE = new_image_by_type($_FILES['binFile']['name'], $FILE_EXTENSION);
imagecopyresampled($NEW_IMAGE, $OLD_IMAGE, 0, 0, 0, 0, $NEW_WIDTH, $NEW_HEIGHT, $ORIGINAL_WIDTH, $ORIGINAL_HEIGHT);
// save image as a jpg and optimize the file size..
imagejpeg($NEW_IMAGE, $file, 85);
$content = file_get_contents($file);
$content = addslashes($content);
$fileSize = filesize($file);
if you need more code you can find it a few post ago, nothing has changed.
by the way for some reason the mysql_real_escape_string doesn't work with pear
Re: $_FILES problem with uploading
Posted: Mon Feb 18, 2008 11:53 am
by coolbung
On line#30
Code: Select all
echo move_uploaded_file($_FILES['binFile']['name'],"C:\\xampp\\tmp");
The move_uploaded_file function expects the second argument to be the destination file name and not the destination folder path. You should be using something like. Also the first argument is the tmp_name as already discussed in one of the posts.
Code: Select all
$dest = "C:\\xampp\\tmp\\".$_FILES['binFile']['name'];
echo move_uploaded_file($_FILES['binFile']['tmp_name'],$dest);
Assuming the above function returns true, you can then use $dest anywhere u need a path to the new file.
Re: $_FILES problem with uploading
Posted: Mon Feb 18, 2008 12:50 pm
by zsines
by the way for some reason the mysql_real_escape_string doesn't work with pear
This function will not work because it is designed to work specifically with a MySQL database. You need to find something that will work with PEAR, such as prepare(). This should do the trick, but for some reason, it does not.
I don't know what else to say, other than if danilefs1 is using PEAR, mysql_real_escape_string will not work. It cannot be interpreted correctly and will throw an error on the page. It will only (and I mean ONLY) work if the entire page is in MySQL references, with out the use of any PEAR tags ($conn->query, fetchRow(), etc.).
This won't work either, because the site needs to function with different types of databases.
He can also not write to the server, due to write restrictions that the organizations using this software (Georgia Southern University to name one) has put into place. So saving to the database is the only option.
Re: $_FILES problem with uploading
Posted: Mon Feb 18, 2008 1:45 pm
by Benjamin
danielfs1 wrote:Well the addslashes wasn't what is corrupting it.
Yes it was.
Re: $_FILES problem with uploading
Posted: Mon Feb 18, 2008 1:50 pm
by danielfs1
Ive taken it in and out and its not causing any problems its self.
Re: $_FILES problem with uploading
Posted: Mon Feb 18, 2008 2:29 pm
by Benjamin
I ran the code locally and the resized image was perfect until it reached the addslashes line. This means that the code works but your running into a problem somewhere along the line inserting it into your database.
Re: $_FILES problem with uploading
Posted: Tue Feb 19, 2008 9:41 am
by danielfs1
Alright, I managed to find some more information and some other examples.
Here is some code that I got to work with some tweaking.
Code: Select all
//IMAGE UPLOAD AND RESIZING
$tmpName = $_FILES['binFile']['tmp_name'];
$name = $_FILES['binFile']['name'];
$size = $_FILES['binFile']['size'];
$fileType = "image/jpeg";
$quality = 100;
$fp = fopen($tmpName, 'rb');
$content = fread($fp, filesize($tmpName));
$im = imagecreatefromstring($content);
$width = imagesx($im);
$height = imagesy($im);
$imgh = 200;
$imgw = $width / $height * $imgh;
$thumb = imagecreatetruecolor($imgw, $imgh);
imagecopyresampled($thumb,$im,0,0,0,0,$imgw,$imgh,$width,$height);
ob_start();
imagejpeg($thumb, "" ,$quality);
$mynewimage = ob_get_contents();
ob_end_clean();
$mynewimage = addslashes($mynewimage);
$sql = $conn->query("INSERT INTO user_extra (user_ID) VALUES ('$id') ON DUPLICATE KEY UPDATE content = '$mynewimage', size = '$size', name = '$name', type = '$fileType'");