doutuan6158 2012-08-24 04:38
浏览 52
已采纳

通过Web应用程序的特定文件夹存储图像并检索它的简单功能?

I am using WAMP and i have a table in my database that needs id,name,pathphoto,and etc. I have a folder in my web application that stores all the photos of the users. And every user can upload a single photo of them and stores it in a specific folder, when users logged in, the photo that match the user will display in user's main page I am using html for my front-end and PHP for my back-end. And if the user decides to change the photo automatically the new photo will overwrite or removed the old photo of the user. What functions to use in this? I need all your suggestions or advice. Thank you.

  • 写回答

1条回答 默认 最新

  • 普通网友 2012-08-24 05:01
    关注

    Here it is how you do it, A rough code. Your html form

    <form enctype="multipart/form-data" action="uploader.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
    Choose a file to upload: <input name="uploadedfile" type="file" /><br />
    <input type="submit" value="Upload File" />
    </form>
    

    and your php page uploader.php

    <?php
    
    // Where the file is going to be placed 
    $target_path = "uploads/";
    
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
    //a destination path with filename. Make sure your uploads folder have read write permission
    
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
        " has been uploaded";
    } else{
        echo "There was an error uploading the file, please try again!";
    }
    
    //Save user info into database along with a filename that has been uploaded, i.e. basename( $_FILES['uploadedfile']['name']
    
    Now you have uploaded file to a folder, when user edits his profile you can delete image using php's unlink function and upload a new image as you have done above
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效