Blom Posted July 30, 2007 Share Posted July 30, 2007 I have a simple php upload script that accepts a selected xml file's details from an external swf file, named upload.php: <?PHP $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['Filedata']['name']); move_uploaded_file($_FILES['Filedata']['tmp_name'], $target_path); echo "The file ". basename( $_FILES['Filedata']['name']). " has been uploaded"; echo file_get_contents($_FILES['Filedata']['tmp_name']); ?> It uploads the file fine, and outputs the first echo, however not the second. I get this in an errorlog file: [Date & Time] PHP Warning: file_get_contents(/tmp/phpTNBGAa) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No such file or directory in /home/ustudios/public_html/blommestein/test/upload.php on line 7 I'm new to php. Any idea of how to get what I'm trying to achieve, that being to echo the uploaded xml file's contents? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/62388-file_get_contents/ Share on other sites More sharing options...
calabiyau Posted July 30, 2007 Share Posted July 30, 2007 I have a simple php upload script that accepts a selected xml file's details from an external swf file, named upload.php: <?PHP $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['Filedata']['name']); move_uploaded_file($_FILES['Filedata']['tmp_name'], $target_path); echo "The file ". basename( $_FILES['Filedata']['name']). " has been uploaded"; //TRY CHANGING BELOW LINE echo file_get_contents($_FILES['Filedata']['tmp_name']); //TO THIS $contents = file_get_contents($target_path); echo $contents; ?> It uploads the file fine, and outputs the first echo, however not the second. I get this in an errorlog file: [Date & Time] PHP Warning: file_get_contents(/tmp/phpTNBGAa) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: No such file or directory in /home/ustudios/public_html/blommestein/test/upload.php on line 7 I'm new to php. Any idea of how to get what I'm trying to achieve, that being to echo the uploaded xml file's contents? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/62388-file_get_contents/#findComment-310495 Share on other sites More sharing options...
Blom Posted July 30, 2007 Author Share Posted July 30, 2007 Thanks for the response. I no longer get the errorlog, but the second is still a blank echo. Try for yourself if you like (if you have an xml file handy, or you could use this http://ustudios.net/blommestein/test/uploads/test.xml ). http://ustudios.net/blommestein/test/Test.swf One more thing, would it be possible to get a file's contents without actually storing it in a directory? That ha dbeen my original intent, I just added the file upload to make sure the $_FILES data was actually being sent. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/62388-file_get_contents/#findComment-310504 Share on other sites More sharing options...
calabiyau Posted July 30, 2007 Share Posted July 30, 2007 Have you checked to make sure the file is actually uploading correctly not just relying on your echo statment, cuz the way you have it, there is no IF before move_uploaded_file, so that script will always echo that the file has been uploaded. Quote Link to comment https://forums.phpfreaks.com/topic/62388-file_get_contents/#findComment-310508 Share on other sites More sharing options...
Blom Posted July 30, 2007 Author Share Posted July 30, 2007 Yes I just confirmed by selecting a new xml file (dblcheck.xml) for upload, and it uploaded. Quote Link to comment https://forums.phpfreaks.com/topic/62388-file_get_contents/#findComment-310511 Share on other sites More sharing options...
calabiyau Posted July 30, 2007 Share Posted July 30, 2007 $contents = file_get_contents("$target_path"); echo $contents; Can't remember, maybe it needs the quotes around it Quote Link to comment https://forums.phpfreaks.com/topic/62388-file_get_contents/#findComment-310527 Share on other sites More sharing options...
Blom Posted July 30, 2007 Author Share Posted July 30, 2007 No it still does the same thing as before, thanks though. What I'm really trying to do is simply echo a chosen xml files contents out, without uploading the xml file to a directory. Is that at all possible? Quote Link to comment https://forums.phpfreaks.com/topic/62388-file_get_contents/#findComment-310568 Share on other sites More sharing options...
trq Posted July 30, 2007 Share Posted July 30, 2007 Once you move the file it is no longer in the tmp directory. You would need to use.... echo file_get_contents($target_path . basename( $_FILES['Filedata']['name'])); What I'm really trying to do is simply echo a chosen xml files contents out, without uploading the xml file to a directory. Is that at all possible? If the file is accessible via the network. Quote Link to comment https://forums.phpfreaks.com/topic/62388-file_get_contents/#findComment-310591 Share on other sites More sharing options...
Blom Posted July 30, 2007 Author Share Posted July 30, 2007 You would need to use.... echo file_get_contents($target_path . basename( $_FILES['Filedata']['name'])); Are you sure? Because I don't know if you noticed: $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['Filedata']['name']); But here's the complete script, uploading, echoing "the file <filename> has been uploaded", but not echoing the xml file contents: <?PHP $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['Filedata']['name']); move_uploaded_file($_FILES['Filedata']['tmp_name'], $target_path); echo "The file ". basename( $_FILES['Filedata']['name']). " has been uploaded"; $contents = file_get_contents($target_path); echo $contents; ?> What I'm really trying to do is simply echo a chosen xml files contents out, without uploading the xml file to a directory. Is that at all possible? What I meant was to echo the contents out without moving it from the temp directory to a directory on my server. Is that possible? By the way good track list whoever uploaded tracks.xml. Quote Link to comment https://forums.phpfreaks.com/topic/62388-file_get_contents/#findComment-311062 Share on other sites More sharing options...
Blom Posted July 30, 2007 Author Share Posted July 30, 2007 If you haven't received a response to your message after a few hours, you may bump your question, by replying to it yourself. Quote Link to comment https://forums.phpfreaks.com/topic/62388-file_get_contents/#findComment-311156 Share on other sites More sharing options...
jscix Posted July 30, 2007 Share Posted July 30, 2007 <?PHP $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['Filedata']['name']); if (move_uploaded_file($_FILES['Filedata']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['Filedata']['name']). " has been uploaded"; $contents = file_get_contents($target_path); print_l ($contents); } else { echo "Error Uploading File."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/62388-file_get_contents/#findComment-311187 Share on other sites More sharing options...
Blom Posted July 30, 2007 Author Share Posted July 30, 2007 <?PHP $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['Filedata']['name']); if (move_uploaded_file($_FILES['Filedata']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['Filedata']['name']). " has been uploaded"; $contents = file_get_contents($target_path); print_l ($contents); } else { echo "Error Uploading File."; } ?> Nope still does the same as the others. Then again I dont see why changing an echo statement to a print statement would help. Thanks anyway though. Quote Link to comment https://forums.phpfreaks.com/topic/62388-file_get_contents/#findComment-311207 Share on other sites More sharing options...
Blom Posted July 30, 2007 Author Share Posted July 30, 2007 Wait a second I just noticed something. Perhaps because the upload is being done from flash, but when I echo basename( $_FILES['Filedata']['name']) or any other part of the filedata array, it comes as blank, however it DOES upload. That is why echo "The file ". basename( $_FILES['Filedata']['name']). " has been uploaded"; actually comes as simply "The file has been uploaded." Could that be part of the problem? If so what the hell is going on? Quote Link to comment https://forums.phpfreaks.com/topic/62388-file_get_contents/#findComment-311211 Share on other sites More sharing options...
calabiyau Posted July 30, 2007 Share Posted July 30, 2007 Try removing the basename() from your $target_path. I think it is meant for when you specify a real path to a real file that already exists, not for something that is in the FILES array EXAMPLE FROM THE MANUAL $path = "/home/httpd/html/index.php"; $file = basename($path); I dunno, just came across that so maybe it is throwing things off. If basename can't operate on something from the files array then that would explain why your echo statement is blank for content. Not sure why it would still do move_uploaded file, but it's something to try anyway. Quote Link to comment https://forums.phpfreaks.com/topic/62388-file_get_contents/#findComment-311328 Share on other sites More sharing options...
hitman6003 Posted July 30, 2007 Share Posted July 30, 2007 What I'm really trying to do is simply echo a chosen xml files contents out, without uploading the xml file to a directory. Is that at all possible? Unless you are on the same network, like Thorpe said, you will have to upload the file, however, you don't have to store it (i.e. use move_uploaded_file to move it to the uploads directory). Use use file_get_contents on the tmpname... echo file_get_contents($_FILES['Filedata']['tmpname']); The file will be destroyed once the script finishes execution. Quote Link to comment https://forums.phpfreaks.com/topic/62388-file_get_contents/#findComment-311338 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.