简体   繁体   中英

How can I upload file to server

I am trying to create a file upload form. The form works correctly and upload the file to my system folder but when I use an online folder ( http://www.google.com/uploadedcv ) it does not work. Please can someone assist me with this?

Here is the code below:

<?php
if(isset($_POST['fileupload'])){
if($_FILES["file"]["error"] > 0)
{
echo "Error: ".$_FILES["file"]["error"] . "<br>";
}

$allowedEXTs = array("cvs","txt");
$extension = @end(explode(".",$_FILES["file"]["name"]));
//$extension = explode(".",$_FILES["file"]["name"]);
//$extension = $extension[1];
//Supported File Type Below:
if(((!$_FILES["file"]["type"] == "application/vnd.ms-excel")||
$_FILES["file"]["type"]=="image/png"||$_FILES["file"]["type"]=="image/jpeg"||
$_FILES["file"]["type"]==("plain/txt")&& ($_FILES["file"]["size"] <20000)
&& in_array($extension,$allowedExts))){

//{echo $_FILES["file"]["type"] ." not supported.";}

if(file_exists("uploadedcv/" .$_FILES["file"]["name"]))
{
echo " Sorry, your CV (" . $_FILES["file"]["name"] . ") already exist in our server.";
}else{
move_uploaded_file($_FILES["file"]["tmp_name"],"http://www.google.com/uploadedcv/" . $_FILES["file"]["name"]);
header('Location: http://www.google.com');
}
}
}
?>


<html>
<head>
<title>File Upload</title>
<style type="text/css">
fieldset{
        background-color: #BDDFFF;
        width:50%;
        }

</style>
</head>

<body>

<form action="" method="post" enctype="multipart/form-data">
<fieldset>
<label>FILENAME</label>
<input type ="file" name="file"/>
<input type="submit" value="upload" name="fileupload"/>
</fieldset>
</form>

</body>
</html>

Please, understand that the above code worked correctly when I tried uploading to my local computer folder. The only issue is uploading to my web folder instead of my local folder.

You can't upload files to another server(its possible only via ftp). And why are you trying to move it to google? oO

Change your code:

move_uploaded_file($_FILES["file"]["tmp_name"],"http://www.google.com/uploadedcv/" . $_FILES["file"]["name"]);

With this:

move_uploaded_file($_FILES["file"]["tmp_name"],"uploadedcv/" . $_FILES["file"]["name"]);

This is for uploading the file in the folder where your code is trying to check if it already exists:

if(file_exists("uploadedcv/" .$_FILES["file"]["name"]))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM