Page 1 of 1

cannot insert image?

Posted: Mon May 17, 2004 3:24 am
by teckyan888

Code: Select all

<?php

$imgf = $_FILES['userfile']['name']; // name of file in user's machine
$imgt = $_FILES['userfile']['type']; // type of uploaded file
$imgs = $_FILES['userfile']['size']; // size of uploaded file, in bytes
$imgtf = $_FILES['userfile']['tmp_name'];  // name of the file temporarily 
                                           // stored in server
$fileError = $_FILES['userfile']['error']; // error code in uploading file, 
                                           // 0 - success

if ($fileError != UPLOAD_ERROR_OK)
{
    echo 'Error in uploading: ';
    switch ($fileError)
    {
        case UPLOAD_ERR_INI_SIZE:
            echo 'File exceeded upload_max_filesize';
            break;
        case UPLOAD_ERR_FORM_SIZE:
            echo 'File exceeded max_file_size';
            break;

        case UPLOAD_ERR_PARTIAL:
            echo 'File only partially uploaded';
            break;

        case UPLOAD_ERR_NO_FILE:
            echo 'No file uploaded';
            break;
    }
}
else
{  
    print "Uploaded file summary:<br>";
    print "image file name in temp dir: $imgtf <br>";
    print "name on user machine: $imgf <br>";
    print "size: $imgs <br>";
    print "type: $imgt <br>";
    print "dir: $myRD<br>";
    print "error: $fileError<br>";

// $fileDir = "../../cart/".$imgf; // CAUSING ERROR...


// $fileDir = "./".$imgf; // 2 level up? script in htdocs/kokch
                       // image loaded in Apache2/htdocs/kokch

// $fileDir = "imgFolder/".$imgf; // current folder's subfolder! script in htdocs/kokch
                       // image loaded in htdocs/kokch/imgFolder

// $fileDir = ".".$imgf; // 2 level up? script in htdocs/kokch
                       // image loaded in Apache2/htdocs/kokch
                        // BUT with file named .dot7.jpg!!

//$fileDir = "/".$imgf; // 5 level up? script in htdocs/kokch
                       // image loaded in c:/ProgramFiles/ApacheGroup/Apache2/htdocs/kokch

//$fileDir = "../".$imgf; // 3 level up? script in htdocs/kokch
                       // image loaded in ApacheGroup/Apache2/htdocs/kokch

$fileDir = "imgFolder/image/".$imgf; // current folder's sub-subfolder! 
                       // script in htdocs/kokch
                       // image loaded in htdocs/kokch/imgFolder/image 

// move to proper destination...
if (move_uploaded_file($imgtf,$fileDir))
	print "success<br>";
else
	print "failed<br>";
}
print "<h1>done...</h1>";


/*
The directory (or folder) named 'image' under the directory 'imgFolder' MUST first be created!

And in Unix/Linux system, you MUST grant the write permission for user
to write onto this directory. For example,

    chmod o+w image

You do not need to do this in Windows OS
*/

?>
When i upload the picture ,it display message like that...

Code: Select all

<?phpUploaded file summary:
image file name in temp dir: C:\WINDOWS\TEMP\phpA.tmp 
name on user machine: HaireP5.jpg 
size: 11435 
type: image/pjpeg 
dir: 
error: 0

Warning: move_uploaded_file(imgFolder/image/HaireP5.jpg): failed to open stream: No such file or directory in C:\Program Files\Apache Group\Apache2\htdocs\upfile.php on line 66

Warning: move_uploaded_file(): Unable to move 'C:\WINDOWS\TEMP\phpA.tmp' to 'imgFolder/image/HaireP5.jpg' in C:\Program Files\Apache Group\Apache2\htdocs\upfile.php on line 66
failed

done...

?>
However ,it show the warning to me...And i cannot insert into my database...Anyone who know what problem,please solve to me!thanks...

Posted: Mon May 17, 2004 5:45 am
by malcolmboston
Your error message tells you
The fabulous PHP error messages wrote: No such file or directory in C:Program FilesApache GroupApache2htdocsupfile on line 66
the problem is with the "mismatch" of syntax from windows to linux

windows requires double \\ for eg

C:Program Files\\Apache Group\\Apache2\\htdocs\\upfile

thats correct i believe