如何使用PHP将图像上传到webhost域?

时间:2014-01-31 09:32:49

标签: php

如果我想将图像上传到文件系统(例如我的域中的文件夹),该怎么办?问题是,我已经尝试在localhost上上传图像,但它工作正常但是当我在我的域中执行它时它不再起作用了。真的不知道这里有什么问题。任何帮助都会做!不管怎样,谢谢。

<form action="adminUploadTry.php" method="post" enctype="multipart/form-data">
<input type="file" name="image" >
<input type="submit" name="submit" value="Upload" >
</form>

<?php
if(isset($_POST['submit'])){
$image_name = $_FILES['image']['name'];
$image_type = $_FILES['image']['type'];
$image_size = $_FILES['image']['size'];
$image_tmp_name = $_FILES['image']['tmp_name'];

if($image_name==''){
    echo "You forgot to select an image. Please choose one!";
    exit();
}

else 
move_uploaded_file(image_tmp_name, "/home/stagcon2/public_html/StagConnect/admin/pictures/$image_name"); 

    echo "Image Succesfully Uploaded!";
    echo "<img src='/home/stagcon2/public_html/StagConnect/admin/pictures/$image_name'>";
}
?>
顺便说一句,这里的问题是我上传图片后会说“成功上传”,但是当我查看我的文件夹时,图片没有保存。

2 个答案:

答案 0 :(得分:0)

您可能忘记$登录image_tmp_name

move_uploaded_file($image_tmp_name, "/home/stagcon2/public_html/StagConnect/admin/pictures/$image_name");

答案 1 :(得分:0)

看看你是否需要在php.ini中增加upload_max_filesize和post_max_size的值:

; Maximum allowed size for uploaded files.
upload_max_filesize = 40M

; Must be greater than or equal to upload_max_filesize
post_max_size = 40M