PHP MySQL图像上传tmp到所选目录

时间:2013-12-12 04:44:27

标签: php mysql image upload

好的,我想将一张图片从我的电脑上传到主机/数据库,一切正常,一切都上传到数据库(图像名称为VARCHAR,只是措辞不是图像),除了图像不需要移动,我得到这个警告:

Upload: 6285.jpg
Type: image/jpeg
Size: 68.1669921875 kB
Temp file: /tmp/php1Be59N

Warning: move_uploaded_file(/public_html/pages/CMX/images/products/oils/6285.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/littlepe/public_html/pages/CMX/pages/extras/allFunctions.php on line 875

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php1Be59N' to '/public_html/pages/CMX/images/products/oils/6285.jpg' in /home/littlepe/public_html/pages/CMX/pages/extras/allFunctions.php on line 875
Stored in: /public_html/pages/CMX/images/products/oils/6285.jpg Upload another? or Go home?

我经历过各种类型的目录,第一个是绝对路径:

/home/public_html/pages/CMX/images/products/oils/6285.jpg
/public_html/pages/CMX/images/products/oils/6285.jpg
/pages/CMX/images/products/oils/6285.jpg
/CMX/images/products/oils/6285.jpg
/images/products/oils/6285.jpg
/products/oils/6285.jpg
/oils/6285.jpg

该目录是可写的和正确的(我会告诉你但是现在还不能发布图像)。

我的表格代码:

    $user_check=$_SESSION['login_user'];

$sqlCommand = "(SELECT * FROM userAccount WHERE email='$user_check')";
$query = mysqli_query($con,$sqlCommand) or die("Error: ".mysqli_error($con));
$column = mysqli_fetch_array($query);

if($column['admin'] != NULL){
    echo "<section class='userName'><h3>".$column['firstName']." ".$column['surname']."</h3></section>";
    echo "<section class='address'>".$column['addressLine1']."<br />".$column['addressLine2']."<br />".$column['county']."<br />".$column['country']."<br />".$column['postCode']."</section>";
    echo "<section class='email'><h3>".$column['email']."</h3></section>";
    echo "<hr />";
    echo "<section class='upNewProduct' style='height:400px;overflow:auto;'><h3>Upload New Product</h3>
        <form action='extras/uploadProcess.php' method='post' enctype='multipart/form-data'>
        Product Name: <input type='text' name='productName' /><br />
        Product Image Sub-Catagory: <select name='prodImgCat' id='prodImgCat'>
                    <option selected>Choose a Sub Catagory for Image</option>
                        <option value='oils/'>Oil</option>
                        <option value='chain/'>Chain</option>
                        <option value='coolant/'>Coolant</option>
                        <option value='filter/'>Filter</option>
                </select><br />
        Product Image: <input type='file' name='productImg' /><br />
        Description: <textarea type='text' name='shortDesc' value='' maxlength='1500' cols='22' rows='6' tabindex='6' id='shortDesc'></textarea><br />
        Features: <textarea type='text' name='longDesc' value='' maxlength='1500' cols='22' rows='6' tabindex='6' id='longDesc'></textarea><br />
        Price: <input type='text' name='price' /> <strong style='font-size:8pt;'>(Do <u>NOT</u> enter &pound; / &dollar; / &euro; currency symbols. &nbsp;&nbsp;&nbsp;&nbsp; <u>ONLY</u> enter numerals. &nbsp;&nbsp;&nbsp;&nbsp; <u>e.g:</u> 99.99 )</strong><br />
        Catagory: <select name='catagory' id='catagory'>
                    <option selected>Choose a Catagory</option>
                        <option value='Helmets'>Helmets</option>
                        <option value='Gloves'>Gloves</option>
                        <option value='Boots'>Boots</option>
                        <option value='Body Protection'>Body Protection</option>
                        <option value='Clothing'>Clothing</option>
                        <option value='Bike Parts'>Bike Parts</option>
                        <option value='Accessories'>Accessories</option>
                </select><br />
        Sub-Catagory: <select name='subCat' id='subCat'>
                    <option selected>Choose a Sub Catagory</option>
                        <option value='Oil'>Oil</option>
                        <option value='Chain'>Chain</option>
                        <option value='Coolant'>Coolant</option>
                </select><br />
        Brand: <select name='brand' id='brand'>
                    <option selected>Choose a brand</option>
                        <option value='100%'>100%</option>
                    <option value='Acerbis'>Acerbis</option>
                    <option value='Airoh'>Airoh</option>
                    <option value='Akrapovic'>Akrapovic</option>
                    <option value='Alias'>Alias</option>
                    <option value='Alpinestars'>Alpinestars</option>
                    <option value='Answer Racing'>Answer Racing</option>
                    <option value='Apico'>Apico</option>
                    <option value='Arai'>Arai</option>
                    <option value='Artrax'>Artrax</option>
                    <option value='Asterisk'>Asterisk</option>
                    <option value='Beer Optics'>Beer Optics</option>
                    <option value='Bell'>Bell</option>
                    <option value='Blackrock'>Blackrock</option>
                    <option value='Bolt'>Bolt</option>
                    <option value='Cycra'>Cycra</option>
                    <option value='Deft Family'>Deft Family</option>
                    <option value='DEP'>DEP</option>
                    <option value='Dragon'>Dragon</option>
                    <option value='DRC'>DRC</option>
                    <option value='Dunlop'>Dunlop</option>
                    <option value='EKS Brand'>EKS Brand</option>
                    <option value='Engine Ice'>Engine Ice</option>
                    <option value='EVS'>EVS</option>
                    <option value='Factory Arme'>Factory Arme</option>
                    <option value='Factory Effex'>Factory Effex</option>
                    <option value='Fly Racing'>Fly Racing</option>
                    <option value='Forcefield Armour'>Forcefield Armour</option>
                    <option value='Forma'>Forma</option>
                    <option value='Fro Systems'>Fro Systems</option>
                    <option value='Gaerne'>Gaerne</option>
                    <option value='Goldentyre'>Goldentyre</option>
                    <option value='GoPole'>GoPole</option>
                    <option value='GoPro'>GoPro</option>
                    <option value='HiFlo Filtro'>HiFlo Filtro</option>
                    <option value='JT Braking'>JT Braking</option>
                    <option value='K-Edge'>K-Edge</option>
                    <option value='Kryptonite'>Kryptonite</option>
                    <option value='Lazer'>Lazer</option>
                    <option value='Leatt'>Leatt</option>
                    <option value='Matrix Concepts'>Matrix Concepts</option>
                    <option value='Mechanix Wear'>Mechanix Wear</option>
                    <option value='Motion Pro'>Motion Pro</option>
                    <option value='Motorex'>Motorex</option>
                    <option value='Muc Off'>Muc Off</option>
                    <option value='No Toil'>No Toil</option>
                    <option value='Oakley'>Oakley</option>
                    <option value='ODI Troy Lee'>ODI Troy Lee</option>
                    <option value='Ogio'>Ogio</option>
                    <option value='One Industries'>One Industries</option>
                    <option value='Park Tool'>Park Tool</option>
                    <option value='POD'>POD</option>
                    <option value='Polisport'>Polisport</option>
                    <option value='Pro Clean'>Pro Clean</option>
                    <option value='Progrip'>Progrip</option>
                    <option value='Putoline'>Putoline</option>
                    <option value='Race FX'>Race FX</option>
                    <option value='Raptor Titanium'>Raptor Titanium</option>
                    <option value='Renthal'>Renthal</option>
                    <option value='Rip n Roll'>Rip n Roll</option>
                    <option value='Risk Racing'>Risk Racing</option>
                    <option value='RK Chains'>RK Chains</option>
                    <option value='SBS Brakes'>SBS Brakes</option>
                    <option value='Science in Sport'>Science in Sport</option>
                    <option value='Scott'>Scott</option>
                    <option value='Seven'>Seven</option>
                    <option value='Shoei'>Shoei</option>
                    <option value='Shot'>Shot</option>
                    <option value='Sidi'>Sidi</option>
                    <option value='SixSixOne'>SixSixOne</option>
                    <option value='SM Pro Platinum'>SM Pro Platinum</option>
                    <option value='Smith'>Smith</option>
                    <option value='Spada'>Spada</option>
                    <option value='Sunline'>Sunline</option>
                    <option value='Suomy'>Suomy</option>
                    <option value='THH'>THH</option>
                    <option value='Thor'>Thor</option>
                    <option value='Troy Lee Designs'>Troy Lee Designs</option>
                    <option value='Twin Air'>Twin Air</option>
                    <option value='Venhill'>Venhill</option>
                    <option value='VP Racing'>VP Racing</option>
                    <option value='Wizard Wash'>Wizard Wash</option>
                    <option value='Yoshimura'>Yoshimura</option>
                    <option value='Zeta'>Zeta</option>
                </select>
                <input id='contactBtn' type='submit' name='submit' value='Submit Product' tabindex='7' />
        </form>
    </section>";

我的PHP代码:

if (!$_POST['productName'] | !$_POST['prodImgCat'] | !$_POST['shortDesc'] | !$_POST['longDesc'] | !$_POST['price'] | !$_POST['catagory'] | !$_POST['subCat'] | !$_POST['brand']){
    die('You did not complete all of the required fields! <a href="http://www.littlepenguindesigns.co.uk/pages/CMX/pages/userAccount.php">Try Again?</a>');
}

$productName = $_POST['productName'];
$prodImgCat = $_POST['prodImgCat'];
$shortDesc = $_POST['shortDesc'];
$longDesc = $_POST['longDesc'];
$price = $_POST['price'];
$catagory = $_POST['catagory'];
$subCat = $_POST['subCat'];
$brand= $_POST['brand'];

$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["productImg"]["name"]);
$extension = end($temp);
if ((($_FILES["productImg"]["type"] == "image/gif")|| ($_FILES["productImg"]["type"] == "image/jpeg")|| ($_FILES["productImg"]["type"] == "image/jpg")|| ($_FILES["productImg"]["type"] == "image/pjpeg")|| ($_FILES["productImg"]["type"] == "image/x-png")|| ($_FILES["productImg"]["type"] == "image/png"))&& ($_FILES["productImg"]["size"] < 200000)&& in_array($extension, $allowedExts)){
    if ($_FILES["productImg"]["error"] > 0){
        echo "Return Code: " . $_FILES["productImg"]["error"] . "<br>";
    }else{
        echo "Upload: " . $_FILES["productImg"]["name"] . "<br>";
        echo "Type: " . $_FILES["productImg"]["type"] . "<br>";
        echo "Size: " . ($_FILES["productImg"]["size"] / 1024) . " kB<br>";
        echo "Temp file: " . $_FILES["productImg"]["tmp_name"] . "<br>";

        if (file_exists("/public_html/pages/CMX/images/products/".$_POST['prodImgCat'].$_FILES['productImg']['name']."")){
            echo $_FILES['productImg']['name']." already exists.";
        }else{

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! LINE 875 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 move_uploaded_file($_FILES['productImg']['tmp_name'], "/public_html/pages/CMX/images/products/".$_POST['prodImgCat'].$_FILES['productImg']['name']);

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

 echo "Stored in: "."/public_html/pages/CMX/images/products/".$_POST['prodImgCat'].$_FILES['productImg']['name']." <a href='http://www.littlepenguindesigns.co.uk/pages/CMX/pages/userAccount.php'>Upload another?</a> or <a href='http://www.littlepenguindesigns.co.uk/pages/CMX/pages/index.php'>Go home?</a>";
        }
    }
}else{
    echo "Invalid file";
}

$productImgLocation = "".$_POST['prodImgCat']."".$_FILES['productImg']['name']."";

$insertProduct = ("INSERT INTO product (productName, productImg, shortDesc, longDesc, price, catagory, subCat, brand) VALUES ('".$_POST['productName']."', '".$productImgLocation."' '".$_POST['shortDesc']."', '".$_POST['longDesc']."', '".$_POST['price']."', '".$_POST['catagory']."', '".$_POST['subCat']."', '".$_POST['brand']."')");
$add_product = mysqli_query($con,$insertProduct);

mysqli_close($con);

所以我的问题就是这个问题,我在这里做错了什么呢?文件和目录都在那里,但它不想从tmp文件夹移动到所选文件夹,请帮忙因为这真的开始让我烦恼。

注意:我的注射等。我完成上传表格后会对代码进行修改,所以请不要发布关于注射等信息,谢谢。

0 个答案:

没有答案