Alright, so it works - kinda.
I had to move the scripts around. I think the first way I had it:
Code:
<?php
$target = "box_images/";
$target = $target .$pictureNum."_box_". basename( $_FILES['uploaded']['name']) ;
$ok=1;
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
chmod($target, 0777);
}
else {
echo "Sorry, there was a problem uploading your file.";
}
}
?>
<?php
$target = "box_images/";
$target = $target .$pictureNum."_banner_". basename( $_FILES['uploaded2']['name']) ;
$ok=1;
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
else
{
if(move_uploaded_file($_FILES['uploaded2']['tmp_name'], $target))
{
chmod($target, 0777);
}
else {
echo "Sorry, there was a problem uploading your file.";
}
}
?>
<?php if ($_FILES['uploaded2']['tmp_name'] == NULL) {
}
else {
error_reporting(E_ALL);
$uploadDir = "/home/gameargu/public_html/tmp/"; // or something similar
$uploadedfile = $uploadDir . basename($_FILES["uploaded2"]["tmp_name"]);
if (move_uploaded_file($_FILES["uploaded2"]["tmp_name"], $uploadedfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "File not saved!\n";
}
// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);
// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);
// For our purposes, I have resized the image to be
// 600 pixels wide, and maintain the original aspect
// ratio. This prevents the image from being "stretched"
// or "squashed". If you prefer some max width other than
// 600, simply change the $newwidth variable
$newwidth=150;
$newheight=($height/$width)*150;
$tmp=imagecreatetruecolor($newwidth,$newheight);
// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
$filename = "games_images/thumbs/".$pictureNum."_".$_FILES['uploaded2']['name'];
imagejpeg($tmp,$filename,100);
echo $filename;
imagedestroy($src);
imagedestroy($tmp);
// NOTE: PHP will clean up the temp file it created when the request
// has completed.
}
?>
It was taking the file and moving it before it actually got to the image resizing script (the last script in that code).
I changed it to:
Code:
<?php if ($_FILES['uploaded2']['tmp_name'] == NULL) {
}
else {
error_reporting(E_ALL);
$uploadDir = "/home/gameargu/public_html/cms/htms/tmp_imgs/"; // or something similar
$uploadedfile = $uploadDir . basename($_FILES["uploaded2"]["tmp_name"]);
if (move_uploaded_file($_FILES["uploaded2"]["tmp_name"], $uploadedfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "File not saved!\n";
}
// Create an Image from it so we can do the resize
$src = imagecreatefromjpeg($uploadedfile);
// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);
// For our purposes, I have resized the image to be
// 600 pixels wide, and maintain the original aspect
// ratio. This prevents the image from being "stretched"
// or "squashed". If you prefer some max width other than
// 600, simply change the $newwidth variable
$newwidth=150;
$newheight=($height/$width)*150;
$tmp=imagecreatetruecolor($newwidth,$newheight);
// this line actually does the image resizing, copying from the original
// image into the $tmp image
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
// now write the resized image to disk. I have assumed that you want the
// resized, uploaded image file to reside in the ./images subdirectory.
$filename = "games_images/thumbs/".$pictureNum."_".$_FILES['uploaded2']['name'];
imagejpeg($tmp,$filename,100);
echo $filename;
imagedestroy($src);
imagedestroy($tmp);
// NOTE: PHP will clean up the temp file it created when the request
// has completed.
}
?>
<?php
$target = "box_images/";
$target = $target .$pictureNum."_box_". basename( $_FILES['uploaded']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
chmod($target, 0777);
}
else {
echo "Sorry, there was a problem uploading your file.";
}
?>
<?php
$target = "box_images/";
$target = $target .$pictureNum."_banner_". basename( $_FILES['uploaded2']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['uploaded2']['tmp_name'], $target))
{
chmod($target, 0777);
}
else {
echo "Sorry, there was a problem uploading your file.";
}
?>
and it seems that the resizer works now. However, my native size image is not working now. Is there a way I could code this so I could have the image resized and also same as a native form with the code that I have above?