English 中文(简体)
使用 PHP 保存 PDF 文件
原标题:Saving a PDF file using PHP
  • 时间:2012-05-25 05:12:00
  •  标签:
  • php
  • upload

我对将 PDF 文件保存到我服务器上的文件夹有问题。 代码曾经工作过, 现在却没有。 我希望它做的是检查是否有人试图在提交表格时上传 PDF, 如果文件字段中存在 PDF, 它会上传它, 然后保存 Mysql 数据库的路径。 代码如下 :

    if (!empty($_FILES[ pdf ])){
          $idir = "../files/PDF/"; //my directory file is supposed to be saved in
          $randomd=rand(0000000,9999999); //creates a random number as filename
          $domain = "http://".$_SERVER[ HTTP_HOST ];  
          $file_ext = strrchr($_FILES[ pdf ][ name ],  . ); grabs file extension. my code checked if the file was a pdf a different way and neither seems to work.
          $destination=$randomd.$file_ext; //new filename
          if ($file_ext== pdf ) {
                move_uploaded_file($_FILES[ pdf ][ tmp_name ], "$idir" . $destination);
                $pdf= $domain."/files/PDF/".$destination;                                             } else { echo("File type not supported.");  
mysql_query("UPDATE tbl_listings SET pdf= $pdf  WHERE listing_id= $lid ");
                                                                            }

如果不是空的话, 它不会工作, 它总是试图上传一个文件, 但当我检查文件夹时, 文件夹里什么都没有, 它不会更新 Mysql 。

问题回答

$_FILES[pdf] 永远不会是空的(当表单已提交时),不管是否选中文件,它总是返回一个数组。

检查 $_FILES[pdf [错误] 4 , 当没有上传文件时, 这将是 4





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...