php - 上传多个文件并将路径保存到数据库时出现问题

标签 php mysql

好吧,基本上我正在遵循这个非常简单的指南,但是,我现在完全迷失了。我不想重新开始,我希望这只是一个小小的调整,但无论如何,这里有错误:

Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to     copy() function cannot be a directory in /I don't want to publicize the path name/html/add.php on line 39

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpqd62Gk' to 'thumbnails/' in /I don't want to publicize the path name/add.php on line 39
Sorry, there was a problem uploading your cover. Please check it is the appropriate size and format.
Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in /I don't want to publicize the path name/add.php on line 52

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpFVlGsv' to 'audio/' in /I don't want to publicize the path name/add.php on line 52
Sorry, there was a problem uploading your song. Please check it is the appropriate size and format. 

这是提交表单后执行的“add.php”:

<?php 
include "db_config.php";

//This is the directory where images will be saved 
$targetp = "thumbnails/"; 
$targetp = $targetp . basename( $_FILES['cover']['artist']); 

//This is our size condition 
if ($uploaded_size > 100000) 
{ 
echo "Your file is too large.<br>"; 
$ok=0; 
} 

//This is the directory where songs will be saved 
$targets = "audio/"; 
$targets = $targets . basename( $_FILES['song']['artist']); 

//This is our size condition 
if ($uploaded_size > 6000000) 
{ 
echo "Your file is too large.<br>"; 
$ok=0; 
} 

 //This gets all the other information from the form 
 $title=$_POST['title']; 
 $artist=$_POST['artist']; 
 $cover=($_FILES['cover']['artist']); 
 $song=($_FILES['song']['artist']); 
 $today = date("Ymd"); 
 $ip = $_SERVER['REMOTE_ADDR'];


 //Writes the information to the database 
 mysql_query("INSERT INTO `Thumbnails` VALUES ( '', '$artist - $title', '$cover', '', '$song', '$title', '$artist',  '$today', '$ip')") ; 

 //Writes the photo to the server 
 if(move_uploaded_file($_FILES['cover']['tmp_name'], $targetp)) 
 { 

 //Tells you if its all ok 
 echo "The file ". basename( $_FILES['cover']['artist']). " has been uploaded, and your information has been added to the directory"; 
  } 
  else { 

  //Gives and error if its not 
  echo "Sorry, there was a problem uploading your cover. Please check it is the appropriate size and format."; 
   } 

   //Duplicate for song
   if(move_uploaded_file($_FILES['song']['tmp_name'], $targets)) 
   { 

    echo "The file ". basename( $_FILES['song']['artist']). " has been uploaded, and your information has been added to the directory"; 
    } 
    else { 

    echo "Sorry, there was a problem uploading your song. Please check it is the appropriate size and format."; 
    } 
    ?> 

也许朝着正确的方向迈出一步将受到极大的赞赏,因为它已经到了感觉就像在屏幕上乱写乱画的地步,但是,我不想从头开始。

最佳答案

尝试

改变

basename( $_FILES['cover']['artist']);

basename( $_FILES['cover']['name']);

关于php - 上传多个文件并将路径保存到数据库时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12990691/

相关文章:

php - 在真实的 Web 服务器而不是 WAMP 中放置用于连接数据库的 php 文件的位置

php - paypal express 集成困惑和 paypal 提供的文件不起作用

mysql - 使得主键+常量可以使用索引

mysql - 无法在mysql中获取一个月的所有日期

php - 查询数据库以取回数组

Mysql将不带空格的字符串与带空格的db字段进行比较

php - 选择数据库中尚未存在的不同值

php - sql 只存储每个用户 1 个请求,忽略其他请求

PHP\MYSQL\AJAX(?) - 挣扎于如何在不调用页面刷新的情况下动态更新表单

mysql select查询如果条件参数为null则忽略该参数