0

Hi there. I appreciate your help as previously. You all are amazing!

I'm not sure my php code is my problem as it checks out ok in syntax checker. Maybe I need a second php file that the first one points to? I know my form is fine. I use them all the time. I may just not understand the process. I have spent hours going through tutorials and cannot get to the bottom of it. I am learning PHP so I appreciate your patience.

Here's what I need to know. Do I only need two files (the html form, and the php), or three files, with the second PHP called by the first? Do I have to contain them inside the upload folder, or do I need to point to a folder apart from those two files that is exclusively for uploaded files to be dropped into? They also talk about a temporary folder where the file is first stored, but I am unclear whether I need to add further code to the PHP file or a second PHP file that instructs the file downloaded to a temp folder to be moved to the upload folder. Where is this temp folder? D I create this temporary folder also and if so, where does it need to be? I have created the upload folder and set all the permissions and made it 777 as I have read it needs to be. Perhaps my problem is incorrect paths? Then to retrieve the uploaded files, do I just access my account via FTP? So far, I am just echoing the failure to upload message, so I know my form is communicating with the php file.

Thank you so much.
Linda

2
Contributors
5
Replies
10
Views
6 Years
Discussion Span
Last Post by Ritzlore
0

Thank you, yes my uploads folder is writeable. Otherwise I am not understanding what you are saying. I went to your link and did not find answers I need there.

I need to see the big picture of what I need to create to get my end result, which is a file that I can retrieve from the uploads folder and use according to our purpose. Am I making this too complicated, or missing a step? Right now I have one html file with form calling one php file which is sending the file into the folder "uploads", which is in a folder with the html form and php files. If this is correct, could the path to the folder in my php file be wrong? Why would I get the echo that the file upload was not successful? As I said, I know my form is communicating with the php file, so the problem must be with the upload of the file.

0

Thank you. Sorry for the delay. Busy week. I did resolve that my path was the problem. When I had the form html file, the php, and the uploads folder all in the same folder, I successfully uploaded several files of different types. This is the basic code that was successful:

<?php 
 $target = "uploads/"; 
 $target = $target . basename( $_FILES['uploaded']['name']) ; 
 $ok=1; 
 if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
 {
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
 } 
 else {
 echo "Sorry, there was a problem uploading your file.";
 }
 ?>

Then I set to work to specify allowed file types, and tried all different ways I found in tutorials, including this one, which the code checker did not find any error with, but I echoed the failure text.

<?php 
 $target = "upload/"; 
 $target = $target . basename( $_FILES['uploaded']['name']) ; 
 $ok=1; 

if (($_FILES["file"]["type"] == "application/msword")
 || ($_FILES["file"]["type"] == "application/pdf")
 || ($_FILES["file"]["type"] == "image/jpg")
 || ($_FILES["file"]["type"] == "image/pjpeg")
 || ($_FILES["file"]["type"] == "image/gif")
 || ($_FILES["file"]["type"] == "image/ping")
 && ($_FILES["file"]["size"] < 500000))
 {
 echo "Your file type is not acceptable or the file is too large. Only MS Word, pdf, jpg, ping, and gif files are permitted, and your upload must be under 500 KB. We apologize for any inconvenience. Thanks."; 
 $ok=0; 
 } 

 if(move_uploaded_file($_FILES['file']['tmp_name'], "uploads/".time().".".$image) )
 {
           echo "You have successfully uploaded your image as follows. Thanks for advertising in Crow Calls.<br/>";
           echo '<img src="uploads/'.time().".".$image.'" />';
} 
elseif(move_uploaded_file($_FILES['file']['tmp_name'], "uploads/".time().".".$application) )
 {
           echo "You have successfully uploaded your file as follows. Thanks for advertising in Crow Calls.<br/>";
           echo '<img src="uploads/'.time().".".$application.'" />';
} 
 else {
 echo "We apologize, there was a problem uploading your file. Please try emailing it to crowcalls@sixcrows.org";
 }
 ?>

Then I tried the one below, same as the first that was successful only I specified types and size, and echoed the success text, only when I went to the folder to check for the file, the folder was empty.

<?php 
 $target = "uploads/"; 
 $target = $target . basename( $_FILES['uploaded']['name']) ; 
 $ok=1; 
      $allowed_filetypes = array('.jpg','.gif','.bmp','.png','.doc','.docx','.pdf');
      $max_filesize = 524288;
 if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
 {
 echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
 } 
 else {
 echo "Sorry, there was a problem uploading your file.";
 }
 ?>
0

Sorry, the middle one is from when I had tried also to have the file show up in the browser as I saw in one tutorial, but I don't need it to do that. I meant to show when I just tried using the type code piece with the original file that did work, and the result was that it echoed the failure text.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.