Jump to content

Recommended Posts

Posted

Hello,

 

I tried to make a form that uploaded files (sp. JPg and GIf), but there were many errors:

 

Warning: move_uploaded_file(file_name.jpg): failed to open stream: Permission denied in /path of the archive that uploads the fileon line X.

 

I thought that it could be a problem of permissions of some file, but I don´t know where is the folder where the uploaded files are, so, I can`t change the permissions of that "unknown" folder :lol:

 

Has anyone any idea about it?

 

The code I used to make this form is this:

 

1) upfile.html

 

 

(...)

<form action="upfile2.php" method="post" enctype="multipart/form-data">

<b>Text:b>

<br>

<input type="text" name="cadenatexto" size="20" maxlength="100">

<input type="hidden" name="MAX_FILE_SIZE" value="100000">

<br>

<br>

<b>Send a new file: </b>

<br>

<input name="userfile" type="file">

<br>

<input type="submit" value="Enviar">

</form>

 

 

1) upfile2.php

 

 

 

<?

 

$cadenatexto = $_POST["cadenatexto"];

echo "You wrote in the text string: " . $cadenatexto . "<br><br>";

 

 

$nombre_archivo = $HTTP_POST_FILES['userfile']['name'];

$tipo_archivo = $HTTP_POST_FILES['userfile']['type'];

$tamano_archivo = $HTTP_POST_FILES['userfile']['size'];

 

if (!((strpos($tipo_archivo, "gif") || strpos($tipo_archivo, "jpeg")) && ($tamano_archivo < 100000))) {

echo "The file size is not correct. <br><br><table><tr><td><td></tr></table>";

}else{

if (move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], $nombre_archivo)){

echo "The file has been uploaded successfully.";

}else{

echo "Error!! .";

}

}

?>

 

 

 

Well, I need help...Pliz :lol:

Posted

I had some trouble trying to do something like that. Turns out it's an ownership thing.

 

You own the folders on your site, but PHP isn't you. I think it's identified as 'nobody'.

 

If you make a folder, say Images, using cPanel File Manager, and set permissions to 777, then have your script move the uploaded files to Images it should work.

 

The relevant line in your script:

if (move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], $nombre_archivo)){

would be

if (move_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'], 'Images/'.$nombre_archivo)){

 

Perhaps not the most articulate answer, but it worked for me. If it's unclear, keep asking and I'll try to explain further. :goof:

Posted

I tried to do the same you did, but... It does not work. The problem is that I dont know the path of the temporary directory.

 

I mean, all webs are in public_html. Ok, if I had a carpet inside 'public_html' called 'my_web'...

 

What should I do? Should I create a directory called 'sent_files' in /public_html/my_web, or I should create it in public_html only?

Posted

I looked again at my script, and it uses copy() instead of move_uploaded_file(). Maybe the move..() is getting the error when your script tries to delete the temporary file?

 

Here's my code:

if (@is_uploaded_file($_FILES["userfile"]["tmp_name"])) {

    copy($_FILES["userfile"]["tmp_name"], "gallery" . $_FILES["userfile"]["name"]);

    echo "<p>".$_FILES["userfile"]["name"]." uploaded successfully.</p>";

  }

 

I think the temporary files are thrown away when the session ends, so copy should be sufficient.

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...