MediaGord Posted March 21, 2010 Share Posted March 21, 2010 Hi I'm new to this whole thing of uploading and having some issues. I keep getting weird characters: ��y����c㈔^����G#�� �4��j�j�\()T� like that, and the image is uploading but it's not renaming the file to the directory I want it in: listing1/01.jpg. Any help would me much appreciated, here is the code: <?php if ((($_FILES["file"]["type"] == "image/jpeg") ) && ($_FILES["file"]["size"] < 20000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; rename("/upload/" . $_FILES["file"]["name"],"/listing1/01.jpg"); $sourceImageFilePath="listing1/01.jpg"; $maxResizeWidth="256"; $maxResizeHeight="192"; //-----------------------------------------------------------------Get image sizes function get_image_sizes($sourceImageFilePath, $maxResizeWidth, $maxResizeHeight) { // Get the width and height of the original image $size = getimagesize($sourceImageFilePath); if($size === FALSE) return FALSE; // Error condition $origWidth = $size[0]; $origHeight = $size[1]; // Change dimensions to fit maximum width and height $resizedWidth = $origWidth; $resizedHeight = $origHeight; if($resizedWidth > $maxResizeWidth) { $aspectRatio = $maxResizeWidth / $resizedWidth; $resizedWidth = round($aspectRatio * $resizedWidth); $resizedHeight = round($aspectRatio * $resizedHeight); } if($resizedHeight > $maxResizeHeight) { $aspectRatio = $maxResizeHeight / $resizedHeight; $resizedWidth = round($aspectRatio * $resizedWidth); $resizedHeight = round($aspectRatio * $resizedHeight); } // Return an array with the original and resized dimensions return array($origWidth, $origHeight, $resizedWidth, $resizedHeight); } // Get dimensions $sizes = get_image_sizes($sourceImageFilePath, $maxResizeWidth, $maxResizeHeight); $origWidth = $sizes[0]; $origHeight = $sizes[1]; $resizedWidth = $sizes[2]; $resizedHeight = $sizes[3]; // Create the resized image $imageOutput = imagecreatetruecolor($resizedWidth, $resizedHeight); if($imageOutput === FALSE) return FALSE; // Error condition // Load the source image $imageSource = imagecreatefromjpeg($sourceImageFilePath); if($imageSource === FALSE) return FALSE; // Error condition $result = imagecopyresampled($imageOutput, $imageSource, 0, 0, 0, 0, $resizedWidth, $resizedHeight, $origWidth, $origHeight); if($result === FALSE) return false; // Error condition // Write out the JPEG file with the highest quality value $result = imagejpeg($imageOutput, $outputPath, 100); if($result === FALSE) return false; // Error condition if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> Any ideas why it would be doing this? Thanks, Gord. Quote Link to comment https://forums.phpfreaks.com/topic/196058-image-upload-and-rename-problems/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.