在将图像从临时文件夹移动到当前文件夹时遇到问题,我的图像保存在数据库中,但没有保存在指定的文件夹中。
Route path: /todos/:id
Request URL: http://localhost:xxxx/todos/36
req.params: { "id": "36" }
app.use('/todos/:id', function (req, res, next) {
console.log('Request Id:', req.params.id);
next();
});
答案 0 :(得分:2)
一个问题是您引用的是temp_name
而不是tmp_name
,并且还试图将文件写入不一定存在的位置。
sql很容易受到sql注入的攻击-最好使用带有绑定参数的prepared statement
-下面给出示例。
if( isset( $_POST['Apply'], $_POST['documentstatus'], $_FILES['pfimg'] ) ){
if( !function_exists( 'createdir' ) ){
/*
recursive build folder path and set
permissions along the path.
ex: createdir( '/folder/folder/folder', 0755 );
*/
function createdir( $path=NULL, $perm=0644 ) {
if( !file_exists( $path ) ) {
createdir( dirname( $path ) );
mkdir( $path, $perm, true );
clearstatcache();
}
}
}
$leave = $_POST['documentstatus'];
$documentstatus = "Pending";
$filename=$_FILES["pfimg"]["name"];
$tempname=$_FILES["pfimg"]["tmp_name"]; # <---- tmp_name not temp_name
$folder = rand( 222,333333 );
$path = sprintf( '/student/%s', $folder );
$target = sprintf( '%s/%s', $path, $filename );
/*
as pointed out, create the folder structure
before attempting to write a file to it
*/
createdir( $path );
$status = move_uploaded_file( $tempname, $target );
$sql='insert into `documentdetails` values (null,?,?,?,?)';
$stmt=$db->prepare( $sql );
if( !$stmt )exit('Bad foo!');
$stmt->bind_param('ssss',$empid,$leave,$target,$documentstatus);
$result=$stmt->execute();
/* better to do redirection in php but might cause `headers already sent errors` depending upon how this is called */
header('Location: documentupload.php');
}
答案 1 :(得分:0)
使用x = np.empty(1)
x[0] = 0.4
f = np.array([3,2,1,0,1,2,3])
y = np.empty(0)
for i in range(len(f)):
if f[i+1] < f[i]:
newx = x[i]*2
y = np.append(y,f[i+1])
x = np.append(x,newx)
elif f[i+1]>f[i] and f[i]==0:
newx = x[i] * 2
y = np.append(y, f[i + 1])
x = np.append(x, newx)
else:
break
move_uploaded_file()