dongshi1914 2013-06-06 22:37
浏览 37

PHP图像上传问题

I'm using a simple form to upload an image and save it into a folder called "images". Here's the form, which is embedded in php.

echo "
<form method = 'POST' action = 'uploadPic.php'>
<input type = 'hidden' name = 'mvID' value = '$mvID' /> 
<input type = 'file' name = 'pic' />
<input type = 'submit' value = 'Upload' />
</form>
";

Where $mvID is an integer.

Here's the upload code:

move_uploaded_file($_FILES['pic']['tmp_name'], "images/" . $_POST['mvID'] . ".jpg");

I want the file to be saved in the folder "images" as $mvID.jpg. Don't worry about file restrictions, I'll take care of that later.

Unfortunately, this doesn't save any files in the folder. It doesn't do anything, like report any errors.

Any help would be appreciated.

  • 写回答

2条回答 默认 最新

  • dongnianwo8289 2013-06-06 22:40
    关注

    First of all you should add error handling, see for example the manual.

    Second, to be able to post a file, you need to add enctype="multipart/form-data" to the form:

    <form method='POST' action='uploadPic.php' enctype='multipart/form-data'>
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度