php:如何在上传之前调整图片大小?简单/最好的方法

时间:2015-04-17 09:24:40

标签: php image upload resize

我正在尝试将我的图片调整为经典的头像大小,我尝试了一些但我无法使其工作:s

如果有人可以提供帮助,那就太好了:D这是我正在使用的代码:

(上传工作)

    <?php
if(isset($_FILES['userfile']['name'])){
    $uploaddir = 'uploads/avatars/';
    $uploadedFileName = $_SESSION['userid'];
    $uploadfile = $uploaddir . basename($_FILES['userfile']['name'], $uploadedFileName);
    $ext = pathinfo($uploadfile, PATHINFO_EXTENSION);

    echo "<p>";

    if (move_uploaded_file($_FILES['userfile']['tmp_name'], "uploads/avatars/".$uploadedFileName.'.'.$ext)) {
      echo "File has been successfully uploaded.\n";
    } else {
       echo "Upload failed";
    }

    echo "</p>";  
} else {
    echo '
    <html>
        <head>
            <meta charset="utf-8" />
            <title>PMM | File Upload</title>
        </head>
        <body>
            <form enctype="multipart/form-data" action="#" method="POST"> 
            <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
            <input name="userfile" type="file" />
            <input type="submit" value="Send File" />
            </form>
        </body>
    </html>';
} ?> 

0 个答案:

没有答案