Jump to content

Recommended Posts

I have this very simple upload script, but i always get my echoed error message and i dont know why. I have set the file permission to chmod 777. Any sugestions?

 

<?php 
$target_path = "../adam/cycling/excel/"; 

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

?> 

Link to comment
https://forums.phpfreaks.com/topic/79437-solved-upload-script/
Share on other sites

i thought i had this solved. The script seems to run but the file is not moved across. Can anyone suggest why. The folder storing the uploads is set to chmod 777

 

<?php
$destination = "../adam/cycling/excel";
  if ($_FILES["file"]["error"] >0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
move_uploaded_file ($_FILES["file"]["tmp_name"] , $destination . $_FILES["file"]["name"]);
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";   
echo $destination;
}
    
?>

 

and this is the form

 

<html>
<body><form action="uploader.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form></body>
</html> 

Link to comment
https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402772
Share on other sites

after using error_reporting(E_ALL); i get the error messgae

 

Warning: move_uploaded_file(adam/cycling/excel/Water lilies.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /homepages/12/d214897219/htdocs/adam/cycling/excel/uploader.php on line 10

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpFWcfC3' to 'adam/cycling/excel/Water lilies.jpg' in /homepages/12/d214897219/htdocs/adam/cycling/excel/uploader.php on line 10

 

but the directory does exsist

Link to comment
https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402786
Share on other sites

Still getting the same error,

 

Warning: move_uploaded_file(/homepages/12/d214897219/htdocs/adam/cycling/excel/../adam/cycling/excelWater lilies.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /homepages/12/d214897219/htdocs/adam/cycling/excel/uploader.php on line 10

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpIpW0pa' to '/homepages/12/d214897219/htdocs/adam/cycling/excel/../adam/cycling/excelWater lilies.jpg' in /homepages/12/d214897219/htdocs/adam/cycling/excel/uploader.php on line 10

Upload: Water lilies.jpg

Type: image/pjpeg

Size: 81.830078125 Kb

Temp file: /tmp/phpIpW0pa

Link to comment
https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402795
Share on other sites

ok this is not solved, but sort of is. When i change the dirname to

 

$path = "../adam/cycling/CSV/";
$destination= dirname($path);

 

I get the error message

Warning: move_uploaded_file(/adam/cyclingBlue hills.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /homepages/12/d214897219/htdocs/adam/cycling/excel/uploader.php on line 11

 

It seems to miss off the last part of $path, but when the directory name is

 

$path = "../adam/cycling/";
$destination= dirname($path);

 

it works fine. What is going on. The directory is there and spelled correctly.

 

Link to comment
https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402804
Share on other sites

thanks

 

That now has the "/" between the folder and the file. But its still missing part of the path i.e the CSV part

 

$path = "../adam/cycling/excel/CSV/";
$destination= dirname($path)."/";

 

error

 

Warning: move_uploaded_file(../adam/cycling/excel/Blue hills.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /homepages/12/d214897219/htdocs/adam/cycling/excel/uploader.php on line 11
Link to comment
https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402808
Share on other sites

well all i want to do is up load a file into the location

 

$path = "../adam/cycling/excel/CSV/";
$destination= dirname($path."/");  

 

When i can path to this address i get the error

 

Warning: move_uploaded_file(../adam/cycling/excelWinter.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /homepages/12/d214897219/htdocs/adam/cycling/excel/uploader.php on line 11

 

When i have the path set as

 

 $path = "../adam/cycling/";   
$destination= dirname($path."/");

 

everything works fine.

Link to comment
https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402858
Share on other sites

Still getting the error

 

Warning: move_uploaded_file(../adam/cycling/excelWinter.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /homepages/12/d214897219/htdocs/adam/cycling/excel/uploader.php on line 11

 

If you look at the error its missing some of the file directory

(../adam/cycling/excelWinter.jpg)

 

this should have (../adam/cycling/excel/CSV/Winter.jpg)

 

Link to comment
https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402863
Share on other sites

This is the upload

 

<?php
error_reporting(E_ALL);
$path = '../adam/cycling/excel/CSV/';
$destination= dirname($path."/");
  if ($_FILES["file"]["error"] >0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
move_uploaded_file ($_FILES["file"]["tmp_name"] , $destination. $_FILES["file"]["name"]);
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";   
}
    
?>

 

and this is the form

 

<html>
<body><form action="uploader.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form></body>
</html> 

Link to comment
https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402870
Share on other sites

<?php
error_reporting(E_ALL);
$path = '../adam/cycling/excel/CSV/';
$destination= $path; //<--changed
  if ($_FILES["file"]["error"] >0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
move_uploaded_file ($_FILES["file"]["tmp_name"] , $destination. $_FILES["file"]["name"]);
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";   
}
    
?>

Link to comment
https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402874
Share on other sites

OR

 

<?php
error_reporting(E_ALL);
$path = dirname(__FILE__)."/CSV/";
$destination= $path;
  if ($_FILES["file"]["error"] >0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
move_uploaded_file ($_FILES["file"]["tmp_name"] , $destination. $_FILES["file"]["name"]);
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";   
}
    
?>

 

i'm kinda lost..

 

i assume you want this

$path = dirname(__FILE__)."/CSV/";
$destination= $path;

 

 

 

 

basically your using dirname incorrectly

 

another option

 

$path = '../adam/cycling/excel/CSV/';

$destination= realpath($path);

 

 

Link to comment
https://forums.phpfreaks.com/topic/79437-solved-upload-script/#findComment-402875
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.