图像旋转不正常

时间:2014-06-05 05:28:36

标签: php gd

我正在尝试使用php旋转图像,图像无法创建jpeg旋转图像。

第一个文件4a.php

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<?php include '4b.php';?>
<?php
function UploadOne($fname)
{
$uploaddir = 'upload/';


if (is_uploaded_file($fname['tmp_name']))
{
$filname = basename($fname['name']);
$uploadfile = $uploaddir . basename($fname['name']);
if (move_uploaded_file ($fname['tmp_name'], $uploadfile))
$res = "File " . $filname . " was successfully uploaded and stored.<br>";
else
$res = "Could not move ".$fname['tmp_name']." to ".$uploadfile."<br>";
}
else
$res = "File ".$fname['name']." failed to upload.";
return ($res);


}
?> 
<body>
<?php
if ($_FILES['file']['name'] != "")
{
    $file_exts = array("jpg", "bmp", "jpeg", "gif", "png");
$upload_exts = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 2000000)
&& in_array($upload_exts, $file_exts))
{
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>";
}
$res = UploadOne($_FILES['file']);
$filname = $_FILES['file']['name'];
echo ($res);
LoadJpeg($_FILES['file']);

//and save it on your server...

}} ?>
<form action="4a.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
<form action="imageup.php" method="post">
<input type="hidden" name="view" value="view">
<br><input type="submit" name="view" value="view"/>
</form>

</body>
</html>

<style>
.sucess{
color:#088A08;
}
.error{
color:red;
}
</style>

4b.php

<?php
function LoadJpeg($fname) {
    $degrees=180;
    //header('Content-type: image/jpeg');
    $f= $fname['name'];
    $source = imagecreatefromjpeg($f);
    $rotate = imagerotate($source, $degrees, 0);
    $j=imagejpeg($rotate,$fname['name'],100);

    ?>
    <img src="upload/<?php echo $fname['name'];?>">
    <img src="upload/<?php echo $j;?>">
    <?php


  //  file_put_contents("upload/".$fname['name'],$j);
}
?>

它表明

  

“无法打开流:第6行的E:\ wamp \ www \ Gomal_FinalTask​​ \ 4b.php中没有此类文件或目录”

1 个答案:

答案 0 :(得分:1)

服务器上上传文件的文件名位于$fname['tmp_name']$fname['name']只是客户端的文件名

将图像加载到图像资源时,您需要使用该条目,即

$f= $fname['tmp_name'];
$source = imagecreatefromjpeg($f);